UDP reading on multiple sockets

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Fri May 22 22:26:55 EDT 2009


In message <27bd949f-80b5-44c9-8e3b-
c12b49c7ed82 at r34g2000vbi.googlegroups.com>, thomas.vogel at likeabird.de wrote:

> The only honest answer would be that I'm totaly unfamiliar with select
> and also the documentation I found wasn't able to clear the picture.
> So are there examples of using select together with sockets available?

select is easy to use. In Python, you just pass it three lists of file-like 
objects (anything that implements fileno in the way described in the docs), 
together with an optional timeout. It will return three corresponding lists, 
being subsets of the ones you passed (which might all be empty if the 
timeout expired). You then just go through each item in each returned list, 
doing reads (or accepts, as appropriate) from the files that have something 
waiting to be read, writing to the ones waiting for something to be written, 
and perhaps reporting errors and closing the ones that report problems. 
That's basically all there is to it.

This example, of how do implement a timeout on I/O 
<http://codecodex.com/wiki/index.php?title=I/O_With_Timeout>, is in C, but 
it should help you get the idea.




More information about the Python-list mailing list