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
Overlapped sockets (such as created with socket()
) cannot be used directly for I/O redirection.
When launching the external process, use CreatePipe()
instead to create anonymous pipes for the redirected STDIN/OUT/ERR handles of the process, then use ReadFile()
and WriteFile()
(or equivilents) with send()
and recv()
to manually proxy the data between the socket and the process yourself via the pipes.
In other words, when data arrives to the socket, read the data from the socket and write it to the STDIN pipe. When the process outputs data, read from the STDOUT/ERR pipes and write it to the socket.