Scanning for local servers, getting a broadcast address

Chris Lyon chris.lyon at spritenote.co.uk
Thu Jun 12 13:05:49 EDT 2003


Thank you all very much for your help.Today is the first chance I've
had to look at all this. This certainly seems to work,and I am
especially greatful for the sockopt element as I don't think I'd have
found those parameters in a month of sundays but of course it
introduces another problem.

How do I handle the responses from the other servers within the same
application?

I obviously can't reply by broadcasting from the other servers it will
all end in noise and collisions.

and since I'm using UDP I have to actually chat with the remote server
that has replied to establish a presence, because I presumably could
loose a servers reply in the co-cofeny that would result if there are
lots of servers.

I seem to be a want to do something a bit like:-

serverdict={}

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.IPPROTO_UDP)
s.bind( ('', 2003) )
while 1:
        (rfd,wfd,efd)=select.select([s],[s],[])
        if s in rfd:
                (string, address) = s.recvfrom(100)
                print 'string: %s' % string
                print 'from: %s' % str(address)
                serverdict[str(address)] = string
                print '--------------------------------'
        if s in wfd:
		s.sendto('hello\n', ('<broadcast>', 2003))
		###wrong obviously
		time.sleep(1)


but the time.sleep(1) is obviously a mistake here.

That seems to mean two different threads one for listening and one for
shouting but again I seem unable to bind the ports without getting
error messages about port already in use.

In the end I will be moving data across TCP so I will be running a TCP
handler here as well.So perhaps I should have the acknowledgements
come back via a TCP connection established by the remote servers back
to the original server, which presumably has to be quite efficient to
deal with the large number (upto about 250 theoretically).

Select therefore seems to be the way to go but how does one get the
write side send out say three messages and sleep within it, or does
one expect the remote servers to send upto n times until they get a
specific acknowledgement.

I'm sorry if this has turned into a 'Please write my programme for me'
but I feel a really horrible solution emerging if I'm not careful.
Once the connections are established I only really wont to get a small
chunk of data back from the remote servers which is a list of
available files so and I shouldn't be needing anything heavy once I've
got past this problem of identifiying the remote machines. On the
windows only version I parsed netview which worked most of the time,
but as I originally said this is now a windows linux endeveor so a
pythonic solution would be SO much more controllable.

Oh what a viscous web we weave when we are trying to get a list of
other machines out there.




More information about the Python-list mailing list