python jsocket RuntimeError <p>I'm trying to write a JSocket server in python using <a href="https://pypi.python.org/pypi/jsocket/1.5" rel="nofollow">jsocket</a>. I've used the example code from the <a href="http://pythonhosted.org/jsocket/" rel="nofollow">jsocket</a> and modified it so that the server replies as soon after it receives a message from the client. When my client tries to receive the response in "client.read_obj()" I get an exception. My code and the stacktrace below:</p> <pre><code> #!/usr/bin/python import jsocket import logging logger = logging.getLogger("jsocket.testJSocket") class MyFactoryThread(jsocket.ServerFactoryThread): def __init__(self): super(MyFactoryThread, self).__init__() self.timeout = 2.0 def _process_message(self, obj): if obj!='': if obj ['message'] == 'new connection': logger.info("new connection") self.socket.send_obj({"dbResult": "result"}) else: logger.info(obj) self.socket.send_obj({"dbResult": "result"}) if __name__ == '__main__': import time import jsocket server = jsocket.ServerFactory(MyFactoryThread) server.timeout = 2.0 server.start() time.sleep(1) client = jsocket.JsonClient() client.connect() client.send_obj({"message":"new connection"}) client.read_obj() client.close() server.stop() server.join() </code></pre> <p>Stacktrace:</p> <pre><code> pi@raspberrypi:~/programming/lights/comms $ sudo python testJSocket.py [2016-02-11 20:28:54,475][DEBUG][tserver][start] Threaded Server has been started. [2016-02-11 20:28:55,479][DEBUG][jsocket_base][accept_connection] connection accepted, conn socket (127.0.0.1,39001) [2016-02-11 20:28:55,481][INFO][jsocket_base][connect] ...Socket Connected [2016-02-11 20:28:55,485][INFO][testJSocket][_process_message] new connection [2016-02-11 20:28:55,486][INFO][tserver][run] client connection broken, closing socket [2016-02-11 20:28:55,487][DEBUG][jsocket_base][_close_connection] closing the connection socket [2016-02-11 20:28:55,488][DEBUG][jsocket_base][_close_socket] closing main socket Traceback (most recent call last): File "testJSocket.py", line 39, in &lt;module&gt; client.read_obj() File "/usr/local/lib/python2.7/dist-packages/jsocket/jsocket_base.py", line 74, in read_obj size = self._msg_length() File "/usr/local/lib/python2.7/dist-packages/jsocket/jsocket_base.py", line 69, in _msg_length d = self._read(4) File "/usr/local/lib/python2.7/dist-packages/jsocket/jsocket_base.py", line 65, in _read raise RuntimeError("socket connection broken") RuntimeError: socket connection broken </code></pre> <p>Any ideas on how to solve this?</p>