Note that there are some explanatory texts on larger screens.

plurals
  1. POPython ForkingTCPServer error
    primarykey
    data
    text
    <p>Help to build python ForkingTCPServer. This server returns an error when client connects to the server. When I use ThreadingTCPServer instead of ForkingTCPServer it works fine. socketFileIO module contains functions for pickle to/from socket: <a href="http://code.activestate.com/recipes/577667-pickle-tofrom-socket/" rel="nofollow">http://code.activestate.com/recipes/577667-pickle-tofrom-socket/</a></p> <p>server.py:</p> <pre><code>import SocketServer, time from socketFileIO import write, read class MyClientHandler(SocketServer.BaseRequestHandler): def handle(self): print self.client_address data=read(self.request) print 'Client:', data time.sleep(10) # for testing write(self.request,data) self.request.close() HOST, PORT = '', 50007 server = SocketServer.ForkingTCPServer((HOST, PORT), MyClientHandler) server.serve_forever() </code></pre> <p>client.py:</p> <pre><code>import socket from socketFileIO import write, read HOST = '127.0.0.1' PORT = 50007 data=["A","B","C","End"] for x in data: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) write(s,x) y=read(s) print 'Server:', y s.close() </code></pre> <p>Error:</p> <pre><code>---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 1469) Traceback (most recent call last): File "c:\Python26\lib\SocketServer.py", line 283, in _handle_request_noblock self.process_request(request, client_address) File "c:\Python26\lib\SocketServer.py", line 525, in process_request pid = os.fork() AttributeError: 'module' object has no attribute 'fork' ---------------------------------------- </code></pre> <p>I have a several other questions:</p> <ol> <li>How to shutdown the server by sending data "End" from client ?</li> <li>How to restrict the number of connections (for example no more then 5) ?</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload