Skip to content Skip to sidebar Skip to footer

When Does Socket.recv() Raise An Exception?

I'm using blocking sockets and I'm quite confused about recv() because I didn't find any decent documentation about it. The official one seems restricted to me. The other thing tha

Solution 1:

To put it simply, recv will throw an exception whenever the underlying socket operation fail. The problem is that it depends on the OS you are on. Here I can guess that you are on Windows, because 10054 is a Windows error code for connection reset. Fortunately, when and why socket operations fail is roughly consistent between OSes (check the Windows documentation for details), and python has a portable solution to identify errors :

import errno
...
if err == errno.ECONNRESET :
    print "connection reset"

Post a Comment for "When Does Socket.recv() Raise An Exception?"