socket module and broadcasts ?

Steve Holden sholden at
Mon Jun 3 13:51:56 CEST 2002

OK, in that case a read of

will be helpful for general background if you aren't used to socket
programming. But that's more useful for TCP. What you need is for your
server to listen on a UDP port, and have the clients do a local broadcast to
that UDP port at IP address (which most routers will ignore,
since that address is intended for LAN only communications).

The sequence of actions required at the server is

    1. Create the socket
    2. Bind it to appropriate address(es)
    3. Use a recvfrom() call to wait for client broadcasts.

The sequence of actions required at the client is

    1. Create the socket.
    2. Bind it to appropriate address.
    3. Use sendto() to broadcast for the server.

Once the server sees the client broadcast it know the client's IP address,
and can use sendto() to return a resposne which will, in turn, give the
client the server's address when it executes a recvfrom().

Hope this helps.

Steve Holden                       
Python Web Programming      

"Markus von Ehr" <markus.vonehr at> wrote in message
news:3CFB14B9.CF8FAA4B at
> Hi Steve,
> Steve Holden wrote:
> > Do you really want your server to have top
> > listen for broadcasts from potential clients?
> that is exactly what I want to do.
> > What if the server and the
> > client are of different IP networks?
> I assume that they are both in the same network, but the server is
> on an embedded system and initially it can be that its IP address is
> unknown, so I want to query for the server and assign an IP address.
> Markus

More information about the Python-list mailing list