Udp Newbie

Blitz3D Forums/Blitz3D Beginners Area/Udp Newbie

Gauge(Posted 2004) [#1]
Can someone who me how to get this to work? It always comes out as 0, which part am i doing wrong? thanks.
Code would help me out tremendously, the simpler the better. smile.


stream=CreateUDPStream(4000)
xstream=CreateUDPStream(2000)
x$="HELLO HELLO HELLO"
WriteLine stream,x$
SendUDPMsg stream,"localhost",2000
Delay 500
RecvUDPMsg(xstream)

msg$=ReadLine(xstream)
Print msg$
WaitKey()


Ross C(Posted 2004) [#2]
I think you need to run two programs at once. One of them the server which sets up the stream, and the other which connects to the server (the client).


SurreaL(Posted 2004) [#3]
Gauge, try making the following modification. Change:

SendUDPMsg stream,"localhost",2000
-to->
SendUDPMsg stream,2130706433,2000

and it'll work :)

The problem was that you were passing the string "localhost" as the integer IP address SendUDPMsg needs to send off it's message (which of course Blitz silently changed to '0' once it realized an integer was needed). If you want to see how you can do name resolution, here are a few functions ripped from my BlitzPlay source which may prove useful:

Function BP_ConvertIp% (IP$)
;-=-=-=Convert an IP from x.x.x.x to integer format.
	Local dot1 = Instr(IP$,".")
	Local dot2 = Instr(IP$,".",dot1+1)
	Local dot3 = Instr(IP$,".",dot2+1)
	Local Octet1% = Mid$(IP$,1,dot1-1)
	Local Octet2% = Mid$(IP$,dot1+1,dot2-1)
	Local Octet3% = Mid$(IP$,dot2+1,dot3-1)
	Local Octet4% = Mid$(IP$,dot3+1)
	Return (((((Octet1 Shl 8) Or Octet2) Shl 8) Or Octet3) Shl 8) Or Octet4
End Function

Function BP_ConvertDomain% (domain$)
;-=-=-=Converts from www.domain.com to integer IP address.
	ips% = CountHostIPs (domain)
	If ips Then
		Return HostIP(ips)
	Else
		Return 0
	End If
End Function
There ya go. The difference is ConvertIP does the work mathematically, while ConvertDomain uses the networking stack to try to do name resolution for us. Hopefully this helps :) And hey if you want to save time why not take a look at my BlitzPlay library.. it takes the grunt work out of UDP ;) See my sig if you're interested.


Gauge(Posted 2004) [#4]
cool got it working. thanks alot.

Surreal: I am going to check out the blitzplay library. I'll let ya know what I think. Thanks


Strider Centaur(Posted 2004) [#5]
Blitz Play is da bomb for client/server interfaces :)