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
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.