Inheriting socket handles on Windows

Discussion in 'Python' started by Iker Arizmendi, Apr 27, 2005.

  1. 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
     
    Iker Arizmendi, Apr 27, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. eino
    Replies:
    1
    Views:
    455
    =?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=
    May 8, 2007
  2. Laszlo Nagy
    Replies:
    1
    Views:
    5,119
    Mark Wooding
    Jan 27, 2009
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    1,034
    Jean-Paul Calderone
    Jan 27, 2009
  4. Laszlo Nagy
    Replies:
    0
    Views:
    601
    Laszlo Nagy
    Feb 1, 2009
  5. Replies:
    5
    Views:
    286
    Reid Thompson
    Jun 10, 2009
Loading...

Share This Page