How to make a socket.recv with nonblock?

Peter Hansen peter at
Tue Dec 18 06:00:27 CET 2001

> I have a program like that:
> HOST=''
> PORT=21567
> 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.)

Peter Hansen, P.Eng.
peter at

More information about the Python-list mailing list