Hi Jojo,
We've made some change about error/disconnection handling recently.
On the latest revision of the trunk,
- on unexpected TCP disconnection : receive_message throws msgutil.ConnectionTerminatedException, send_message throws socket.error with "[Errno 32] Broken pipe" (Linux) / "[Errno 10053] An established connection was aborted ..." (Windows)
- on disconnection due to receiving an invalid frame : receive_message throws msgutil.InvalidFrameException
- on disconnection due to receiving closing handshake : receive_message returns None
InvalidFrameException is sub-class of ConnectionTerminatedException, so you can simply catch ConnectionTerminatedException for handling unexpected disconnection and check None for clean closure.
On the latest release 0.5.2,
- on unexpected TCP disconnection : receive_message throws msgutil.MsgutilException, send_message throws socket.error
- on disconnection due to receiving closing handshake (HyBi 76 and later) : receive_message throws msgutil.ConnectionTerminatedException
Note that in this release, ConnectionTerminatedException can be thrown in some other cases, too.
- receive_message is called after receiving closing handshake
- send_message is called after sending closing handshake (i.e. after calling msgutil.close_connection(request))
On the latest revision of the trunk, these error cases are handled by catching msgutil.BadOperationException instead.
We'll keep making this kind of refactoring on exception definitions to clarify and tell the cause of error/disconnection to handler. Please watch msgutil.py for update on exception definition.
Best