Re: Porting Unix sockets code: socket connection to a child
- From: "Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx>
- Date: Tue, 5 Feb 2008 13:24:18 -0600
"Dom Fulton" <wes104@xxxxxxxxx> wrote in message
news:674kp3pbha0ipso42g2cb8gpl4v99fp2l7@xxxxxxxxxx
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?
Are you wanting the child to have the socket mapped as its stdin/stdout?
This is exactly what pipes were designed for.
Use a pipe, all the unix socket read/write functions should work just fine
with a pipe.
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
.
- Prev by Date: Re: TCP/IP recv problem with 2960 byte or bigger buffers
- Next by Date: Removing a Process from the Linked List
- Previous by thread: Is DbgView's timestamp reliable?
- Next by thread: Removing a Process from the Linked List
- Index(es):
Relevant Pages
|