UDP Multiplayer

Blitz3D Forums/Blitz3D Programming/UDP Multiplayer

KillerX(Posted 2008) [#1]
Hello
What is wrong with this code?
Global NumberofPlayers = 1;Input("How many players are there?")
Dim IPAdress(NumberofPlayers)
IPAdress(1) = 1921680101
Variable$ = "Hello World!"
Stream = CreateUDPStream(828)
NewStream = CreateUDPStream(0)
WriteString(Stream,Variable)
Broadcast(Stream,828)
RecvUDPMsg(NewStream)
String1$ = ReadString(NewStream)
Print String1
WaitKey
End


Function Broadcast(Message,Port);Message is the stream that is being broadcasted.  Port is the Destination Port.
Write"Testing..."
For Loop = 1 To NumberofPlayers
SendUDPMsg Message,IPAdress(Loop),Port

Next
Print"done."
End Function

When I run this, the ReadString Function doesn't return anything. Please point out any mistakes with it.


Snarkbait(Posted 2008) [#2]
That's not the way you do integer IP address. You have to convert from dotted to integer.


Snarkbait(Posted 2008) [#3]
hmmm... testing, even with a proper IP it doesn't work. Too bad the UDP commands are so poorly documented.


nawi(Posted 2008) [#4]
http://www.blitzbasic.com/codearcs/codearcs.php?code=1230


KillerX(Posted 2008) [#5]
Can you please post an example of the format for an integer IP adress


Snarkbait(Posted 2008) [#6]
take the number between each dot, convert to hex, put together

192.168.01.01 =
c0 . a8 . 01. 01 =

$c0a80101


Snarkbait(Posted 2008) [#7]
see this example of setting up udp

http://www.blitzbasic.com/codearcs/codearcs.php?code=1593


Wings(Posted 2008) [#8]
in general..

dont mix upp server and client in same code.. you comfuse yourself :D


KillerX(Posted 2008) [#9]
I have gotten it working. Thanks for your help. The mistake other than the IP adress was the port I was sending it to. I was sending it to the port number of the sending stream instead of the port of the redeiving stream. Here is the working code:
Global NumberofPlayers = Input("How many players are there?")
Dim IPAdress(NumberofPlayers)
IPAdress%(1) = $c0a80065
Variable$ = "Hello World!"
Stream% = CreateUDPStream(828)
NewStream% = CreateUDPStream(79)
WriteString(Stream,Variable)
Broadcast(Stream,79)
.reread;This is so it will re-receive the Data If the First RecvUDPMsg failed
RecvUDPMsg(NewStream)
String1$ = ReadString$(NewStream)
If String1 = 0 Goto reread
Print String1
string1 = 0
WaitKey
End


Function Broadcast(Message,Port);Message is the stream that is being broadcasted.  Port is the Destination Port.
For Loop = 1 To NumberofPlayers
SendUDPMsg Message,IPAdress(Loop),Port

Next
End Function