Inheriting socket handles on Windows

I

Iker Arizmendi

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top