How to make a socket.recv with nonblock?

Peter Hansen peter at engcorp.com
Tue Dec 18 00:00:27 EST 2001


> I have a program like that:
> HOST=''
> PORT=21567
> ADDR=(HOST,PORT)
> udpSerSock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
> udpSerSock.bind(ADDR)
> ipsock=socket.socket(socket.AF_INET,10,8)
> while 1:
>  recvpack=ipsock.recv(1024)
>  ....
>  data,addr=udpSerSock.recvfrom(1024) 
> # I want to only make this sentence with nonblock at port 21567
> # notice that this sentence is in loop.

Have you looked in the documentation for the socket module, in the
subsection on the Socket class?  Look for "Socket.setblocking()".

(By the way, "statement" would probably be the better word to
use above.  "sentence" sounds unusual to an English speaker.)

Regards,
-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list