socket module and broadcasts ?

Steve Holden sholden at holdenweb.com
Mon Jun 3 07:51:56 EDT 2002


OK, in that case a read of

        http://www.mcmillan-inc.com/sock1.html

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 255.255.255.255 (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.

regards
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------


"Markus von Ehr" <markus.vonehr at ipm.fhg.de> wrote in message
news:3CFB14B9.CF8FAA4B at ipm.fhg.de...
> 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