Link to home
Start Free TrialLog in
Avatar of SciFiFreak
SciFiFreak

asked on

UDP broadcast client/server example in Python

I am looking for an UDP broadcast client/server example in Python. Any hints?
Avatar of pepr
pepr

Focus on the built-in module socket (Python doc "7.2 socket -- Low-level networking interface"). See the examples:

http://www.qiksearch.com/python/sockets/server.py 
http://www.qiksearch.com/python/sockets/client.py

They are a bit old and could be written aestetically better, but they show the principle. (Add the line UDPSock.sendto('', addr) before the break to finish the server when sending empty line.)

Later, you may get info and inspiration in the standard module SocketServer Python doc ("11.16 SocketServer -- A framework for network servers")
Avatar of SciFiFreak

ASKER

I am not sure if the above links provides UDP "Broadcast". What I have in mind is a client that is able to send an UDP message that will be received by a group of servers listening to the same certain port (of course, in difference computers of the same network). From what I could understand from the examples above, there is not much of a difference between the UDP approach and a regular TCP approach where the client must know in advance the IP of the server.
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
UDP is simpler than TCP. It does not check delivery and does not ensure that the packets are received in the sent order. See http://en.wikipedia.org/wiki/User_Datagram_Protocol
In the addr I used 127.0.0.255 and it worked fine! Thanks for your help!