UDP broadcast
Posted: Wed May 30, 2012 6:20 am
Hi.
I tried yesterday doing this
http://www.purebasic.fr/english/viewtop ... st#p365942
It does two things:
1. Set up a UDP server and monitor incomming connections
2. Set up a UDP client and send stuff to broadcast address (ie like 192.168.0.255 so it gets distributed to all computers in that network range)
So what you send should be received on all computers in the netwrok.
From the PC side this works great.
On the MAC side it works great to receive, but to send UDP to broadcast address doesnt work. Is there a trick to this?
Here is a small sample program:
I tried yesterday doing this
http://www.purebasic.fr/english/viewtop ... st#p365942
It does two things:
1. Set up a UDP server and monitor incomming connections
2. Set up a UDP client and send stuff to broadcast address (ie like 192.168.0.255 so it gets distributed to all computers in that network range)
So what you send should be received on all computers in the netwrok.
From the PC side this works great.
On the MAC side it works great to receive, but to send UDP to broadcast address doesnt work. Is there a trick to this?
Here is a small sample program:
Code: Select all
InitNetwork()
OpenWindow(0,0,0,640,480,"")
StringGadget(0,0,0,320,50,"TEXT")
ButtonGadget(1,350,0,60,20,"SEND")
CreateNetworkServer(0, 5556, #PB_Network_UDP)
*DataBuffer = AllocateMemory(2048)
*ipbuf = AllocateMemory(1000)
ExamineIPAddresses()
Repeat
Result = NextIPAddress()
If Not result
Break
EndIf
Debug IPString(result)
String$ + IPString(result)+";"
ForEver
PokeS(*ipbuf,string$,Len(string$))
Repeat
event=WindowEvent()
If event=#PB_Event_CloseWindow
End
ElseIf event=#PB_Event_Gadget And EventGadget()=1
For ss=1 To CountString(string$,";")
resultt.s=StringField(string$,ss,";")
myip$ =StringField(resultt.s,1,".")+"."+StringField(resultt.s,2,".")+"."+StringField(resultt.s,3,".")+".255"
Connection = OpenNetworkConnection(myip$, 5556, #PB_Network_UDP) ;chjange to my IP broadcast
Debug "DOCONNECTION "+myip$
If Connection
*DataBuffer2 = AllocateMemory(2048)
PokeS(*DataBuffer2, GetGadgetText(0))
SendNetworkData(Connection, *DataBuffer2, Len(GetGadgetText(0)))
CloseNetworkConnection(Connection)
FreeMemory(*DataBuffer2)
EndIf
Next
EndIf
If NetworkServerEvent()
Client = EventClient()
No = ReceiveNetworkData(Client, *DataBuffer, 2048)
If No
call1.s=FormatDate("%yyyy-%mm-%dd %hh:%ii",Date())
Debug PeekS(*DataBuffer)
SendNetworkData(Client, *ipbuf, Len(String$))
EndIf
CloseNetworkConnection(Client)
EndIf
Delay(50)
ForEver