Re: Porting Unix sockets code: socket connection to a child

Tech-Archive recommends: Fix windows errors by optimizing your registry




"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


.



Relevant Pages

  • 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)
  • Porting Unix sockets code: socket connection to a child
    ... I'm porting a Unix app which creates a child process, ... to the new process via a socket [this is a client/server application, ... the client talks to the child via a socket]. ...
    (microsoft.public.win32.programmer.kernel)
  • 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)
  • Re: Passing a GUI handle to a socket and Postmessage back to GUI
    ... want to pass the handle (of one child) to a server socket class so it can post a message to the child window when data is received. ... In a sockets context it is extremely confusing to name CServer 'client'. ...
    (microsoft.public.vc.mfc)
  • Re: Help with sockets in block mode, please
    ... I need to share connection (socket channel) for child proccess. ... proc acceptConnection { ... client) to decrease resource usage? ...
    (comp.lang.tcl)