Hello all.
I'm trying to get a server process to do the following on both Linux and Windows:
1) Create a socket and bind it to some port number. 2) Use spawnl to create other processes that will then listen and accept on that socket.
On Linux I've managed to do that by using command line args to pass the FD number of the listening socket to the spawned processes. Eg:
# SERVER # s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 9999)) s.listen(5) exe = "childscript" fds = str(s.fileno()) pid = os.spawnl(os.P_NOWAIT, exe, exe, fds)) print "process spawned" time.sleep(5)
# CLIENT # where fds was received from the parent # fds = int(sys.argv[1]) s = socket.fromfd(fds, socket.AF_INET, socket.SOCK_STREAM) s.listen(5) print "child listening..."
However, this fails on Windows as it doesn't have the fromfd function. Aren't WinSock handles inherited by default? And if so, is there some other way to perform a listen()/accept() in this case?
Regards, Iker Arizmendi
-- http://mail.python.org/mailman/listinfo/python-list