Sockets – socket passing between processes

ipcsocketstcpwinsock

Is there a way to pass a socket between processes (not same address space) in Windows?

I find this info Shared Sockets, therefore believe that it is possible.

"The WSADuplicateSocket function is introduced to enable socket sharing across processes"…

More info : at source code of Apache (httpd-2.2.11-win32-src.zip) have usage for api WSADuplicateSocket with comments.

[EDIT]
Recently I find this great sample about this question.
How duplication is done in the unmanaged world – Socket Duplication – Part 1
Is it possible to transfer sockets from unmanaged processes? – Socket Duplication – Part 2

Best Solution

See the Remarks section of WSADuplicateSocket. It effectively says you can use Your Favorite Interprocess Communication Scheme to send the WSAPROTOCOL_INFO structure (it's just data!) to the target.

There are lots of IPC schemes. I'd probably use shared memory with Boost::interprocess. But you could use SendMessage if the target has a window + message loop. Or the Clipboard API, for that matter (though somewhat weird). The mechanism is your choice.