title: error is [Errno 131] Connection reset by peer followed by error: [Errno 9] Bad file descriptor
body: <p>I am using a python chat room server <a href="http://www.daniweb.com/software-development/python/threads/78535/python-chat-server" rel="nofollow">from this code</a> but I am having a issue in running with the client's exceptional behaviour, my server hangs and stops working when my Android client switches to another network and then switches back to chat server network.
  first I get the error </p>
  
  <pre><code>error is [Errno 131] Connection reset by peer 
  </code></pre>
  
  <p>and then   </p>
  
  <pre><code>error: [Errno 9] Bad file descriptor
  </code></pre>
  
  <p>I want to handle this in my Chat server code and keep it up running always either client connects or disconnects, 
  the detailed exception is</p>
  
  <pre><code>---------------------------------------------
  error is [Errno 131] Connection reset by peer
  ---------------------------------------------
  
  Exception happened during processing of request from ('192.168.2.46', 43160)
  Traceback (most recent call last):
   File "/usr/local/lib/python2.7/SocketServer.py", line 582, in process_request_thread
  self.finish_request(request, client_address)
  File "/usr/local/lib/python2.7/SocketServer.py", line 323, in finish_request
  self.RequestHandlerClass(request, client_address, self)
   File "/usr/local/lib/python2.7/SocketServer.py", line 640, in __init__
  self.finish()
  File "/home/rahulm/datagroup.py", line 242, in finish
  self.roomcast('\n  %s has disconnected  *\n' % self)
   File "/home/rahulm//datagroup.py", line 341, in roomcast
  listener.request.send(data)
  error: [Errno 32] Broken pipe
  ----------------------------------------
  error is [Errno 9] Bad file descriptor
  ----------------------------------------
  
  Exception happened during processing of request from ('192.168.2.63', 40460)
  Traceback (most recent call last):
  File "/usr/local/lib/python2.7/SocketServer.py", line 582, in process_request_thread
  self.finish_request(request, client_address)
  File "/usr/local/lib/python2.7/SocketServer.py", line 323, in finish_request
  self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python2.7/SocketServer.py", line 640, in __init__
  self.finish()
  File "/mnt/usb/PirateBox/Shared/datagroup.py", line 242, in finish
  self.roomcast('\n  %s has disconnected  *\n' % self)
  File "/mnt/usb/PirateBox/Shared/datagroup.py", line 341, in roomcast
  listener.request.send(data)
  File "/usr/local/lib/python2.7/socket.py", line 170, in _dummy
  raise error(EBADF, 'Bad file descriptor')
  error: [Errno 9] Bad file descriptor
  ----------------------------------------
  </code></pre>
  
  <p>Note:- I am running chat server in the embedded device So I cant use Twisted 
  any help most appreciated.
  Thanks in Advance !!! </p>