Porting Unix sockets code: socket connection to a child



I'm porting a Unix app which creates a child process, and which talks
to the new process via a socket [this is a client/server application,
rather like telnet, where the server creates a new child process, and
the client talks to the child via a socket].

I've spent a lot of time on MSDN and Google trying to do this, and I
think I'm pretty much there. However, one thing that's puzzled me is
that MSDN doesn't have any example code to do this; all the examples
talk to child processes via pipes, not sockets. I think I may have
found the reason in this thread:

<http://groups.google.co.uk/group/microsoft.public.win32.programmer.kernel/browse_frm/thread/4d3ceb02e00f4289/98bb5b35f1d05e3f?hl=en&tvc=1&q=socket+hstdoutput+hstderror#98bb5b35f1d05e3f>

In short, it seems to be impossible to talk to an arbitrary child
process using a socket. You have to duplicate a socket to do this,
using WSADuplicateSocket, and you can't do this without source code
modifications to the child.

My head is still spinning from this. Surely it must be possible to
talk to an arbitrary child using a socket? Or do I really have to
write some extra pipe code, and then interface the pipe to my socket?
Maybe I can create a thread, rather than a process?

If I have to do the pipe/socket interface, I don't suppose anyone can
point me to any example code? The best example I've had so far is HP's
netperf source
(http://www.netperf.org/svn/netperf2/tags/netperf-2.4.3/src/netserver.c),
but it does seem to make exactly this mistake:

/* Pass the server_sock as stdin for the new process. */
/* Hopefully this will continue to be created with the OBJ_INHERIT
attribute. */
si.hStdInput = (HANDLE)server_sock;

Thanks -

- Dom
.



Relevant Pages

  • Re: Porting Unix sockets code: socket connection to a child
    ... to the new process via a socket [this is a client/server application, ... the client talks to the child via a socket]. ... write some extra pipe code, and then interface the pipe to my socket? ...
    (microsoft.public.win32.programmer.kernel)
  • Re: send to socket: Bad file descriptor
    ... > and i read data on this socket in a child task ... > i want to write data to this socket with a other child but i have this message ... Sounds like you created the child process before creating ... file descriptors, so accessing the same file descriptor ...
    (comp.os.linux.development.system)
  • Re: multithreaded dialog application
    ... multiple threads, a rewrite of the piece of crap in the MSDN. ... the socket messages are posted to the main thread to be processed. ... Nearly all the socket messages are simply passed on to a child dialog ... If you have only one network interface then there ...
    (microsoft.public.vc.mfc)
  • Re: forking in c
    ... the very last child it prints out says it has a parent id ... each child process should have a child process of their own. ... The next statement the child executes is ...
    (comp.unix.programmer)
  • TCP Server+perl
    ... Client each time a new connection is established at the Socket. ... each child completes processing it closes/ends. ... # Main loop control variable ... You exit the ...
    (comp.lang.perl.misc)