1

I am using a python chat room server from this code 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

error is [Errno 131] Connection reset by peer 

and then

error: [Errno 9] Bad file descriptor

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

---------------------------------------------
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
----------------------------------------

Note:- I am running chat server in the embedded device So I cant use Twisted any help most appreciated. Thanks in Advance !!!

slashRahul
  • 555
  • 5
  • 18
  • Your socket connection was probably closed before `listener.request.send(data)` the file descriptor is the os handle system whenever you open a port the os opens it like an open file when you close it the file is cleared. – Kobi K Jun 17 '14 at 06:51
  • thanks Kobi K, So what can be the solution for this ? can you suggest any please ? – slashRahul Jun 17 '14 at 07:02
  • I would just debug my code to see if there is a closing action for the connection for either server or client, you can ratify that this is your problem by commenting the final send at your `finish()` method – Kobi K Jun 17 '14 at 07:17
  • I commented this line 'self.request.close' in the finish() method but still not working can you please be more specific and help ? – slashRahul Jun 17 '14 at 08:42
  • It's really hard to say it without any code, if you can attach the relevant code it will be easier to check it. – Kobi K Jun 17 '14 at 08:55
  • My complete sample code is pasted here at [pastebin link](http://pastebin.com/5ffkpvSA) please see if you can make it out working anything from it. – slashRahul Jun 17 '14 at 09:56

0 Answers0