UDP Multiplayer
Blitz3D Forums/Blitz3D Programming/UDP Multiplayer| 
 | ||
| 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. | 
| 
 | ||
| That's not the way you do integer IP address. You have to convert from dotted to integer. | 
| 
 | ||
| hmmm... testing, even with a proper IP it doesn't work. Too bad the UDP commands are so poorly documented. | 
| 
 | ||
| http://www.blitzbasic.com/codearcs/codearcs.php?code=1230 | 
| 
 | ||
| Can you please post an example of the format for an integer IP adress | 
| 
 | ||
| take the number between each dot, convert to hex, put together 192.168.01.01 = c0 . a8 . 01. 01 = $c0a80101 | 
| 
 | ||
| see this example of setting up udp http://www.blitzbasic.com/codearcs/codearcs.php?code=1593 | 
| 
 | ||
| in general.. dont mix upp server and client in same code.. you comfuse yourself :D | 
| 
 | ||
| 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
 |