UDP sockets
Andrew Bennetts
andrew-pythonlist at puzzling.org
Wed Oct 22 08:02:00 EDT 2003
On Wed, Oct 22, 2003 at 11:15:35AM +0200, Zunbeltz Izaola wrote:
> Hi
>
> I'm porting a client writen in C++ to python. What is the way to get a
> timeout in an select for one socket?
> the c++ code is:
>
>
> FD_ZERO(&fds);
> FD_SET(fd_sock, &fds);
> tv.tv_sec=2;
> tv.tv_usec=0;
> n = select(fd_sock+1,&fds,NULL,NULL,&tv);
> sendto(...)
The python code is (assuming your socket.socket object is in a variable
called 'sock'):
import select
r, w, e = select.select([sock], [], [], 2)
if r:
sock.sendto(...)
-Andrew.
More information about the Python-list
mailing list