views:

524

answers:

2

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.

+1  A: 

If you're creating the child process there are some things that might do it for you. See

http://www.tangentsoft.net/wskfaq/articles/passing-sockets.html (I know that this one worked in the ancient past; no idea if it works on current versions)

http://msdn.microsoft.com/en-us/library/ms682499.aspx

-- MarkusQ

MarkusQ
+1  A: 

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.

Jason S