Redirect IO of process to Windows socket

前端 未结 4 585
轻奢々
轻奢々 2021-01-14 02:50

I am new to winsock, I tried to write a server socket that accepts new connection, then it calls an external executable file. How can we redirect the stdin and stdout of the

4条回答
  •  忘掉有多难
    2021-01-14 03:30

    Windows treats almost everything as a HANDLE. Sockets, which aren't kernel objects, are an exception, and they can't be used for redirection. You'll need to use a pipe, and if you need to send data to/from a socket, you'll need a helper process to copy data between the pipe and socket.

    Have a look at netcat source code for the win32 version (if you can find it), it does pretty much exactly socket <-> stdin and stdout forwarding.

提交回复
热议问题