Networking Q?

Blitz3D Forums/Blitz3D Beginners Area/Networking Q?

Paul "Taiphoz"(Posted 2004) [#1]
First time in here for ages. but here goes anyway.

Server >>
;
; Server Test.
;
;	Simple test to see if I can create a server that will accept a connection
;	and reply to it with a bit of data.
;


Graphics 400,200,16,2
SetBuffer BackBuffer()
ClsColor 0,100,0

;
;	Server Details.
;
Global Server_IP%,Server_IPaddress$,Server_Port%,Server_Stream,Server_Lastmsg$

n 					= CountHostIPs("")
Server_IP 			= HostIP(1)
DebugLog server_ip

Server_IPaddress$ 	= DottedIP$(Server_IP)
Server_Port 		= 2222
Server_Stream		= CreateUDPStream(Server_Port)
Server_Lastmsg$		= "None Recvd"

;
;	Font Setup
;

Global font
font=LoadFont("Courier New",13,1)
Color 0,255,0
SetFont font

Repeat
	ClsColor 0,60,0
	Cls

		Text 1,1, "Server Running on Port  :"+UDPStreamPort(Server_Stream)
		Text 1,10,"Server Running on IP    :"+Server_IPaddress$
		Text 1,20,"+++++++++++++++++++++++++++++++++++++"
		Text 1,40,Server_Lastmsg$
				
		RecvUDPMsg(Server_Stream)
		t=ReadString (Server_Stream)
		If T<>0 Then DebugLog t
		If t<>"" Then Server_Lastmsg$=ReadString (Server_Stream)
	Flip
Until KeyHit(1)

End
CloseUDPStream Server_Stream




Client >>
;
; Server Test.
;
;	Simple test to see if I can create a server that will accept a connection
;	and reply to it with a bit of data.
;


Graphics 400,200,16,2
SetBuffer BackBuffer()
ClsColor 0,100,0

Global font
font=LoadFont("Courier New",13,1)
Color 0,255,0
SetFont font


;
;	UDP Connection Details.
;

Global Send_Stream,Send_IP
Send_Stream=CreateUDPStream(2221)
Send_IP=-1832933770

Repeat
	ClsColor 0,60,0
	Cls
		Text 1,1,"Connecting to  :: "+Send_IP+" on port 2222"
		Locate 1,10:Input txtmsg$
		Text 1,30,"Sending MSG ::"+txtmsg$
		WriteString Send_Stream,txtmsg$
		SendUDPMsg(Send_Stream,Send_IP,2222)
		
	Flip
Until KeyHit(1)

End
CloseUDPStream Stream



What am I doing wrong


Paul "Taiphoz"(Posted 2004) [#2]
elp ?


eBusiness(Posted 2004) [#3]
Nailed it.

Learn how to use Input
Learn to use the correct variable types
Learn that if you read from a stream twice, you will not read the same

Only 3 bugs, if you had been emplyed by Microsoft it would have worked ;)


Paul "Taiphoz"(Posted 2004) [#4]
OK DOH on the input line. been a while from the last time I used it.

As for the Var types and Streams this is my first try with the udp command set. So im not sure what im doing wrong. so any chance you could point it out.


eBusiness(Posted 2004) [#5]
Sorry, you never state t$, so it's an integer where you need a string (probably also a DOH).

And when you call readstring, it will read from where you stopped reading last, this is usefull when a stream contain more than one string. Anyway:

Server_Lastmsg$=t instead of Server_Lastmsg$=ReadString (Server_Stream) should work.

I hope it will work for you too :)


Paul "Taiphoz"(Posted 2004) [#6]
Ahh Damn.

Yeah I didnt notice that I was calling that twice. I was only trying to debug it and forgot to take that code out.

LOL

Got it now.. thanks for the help.