socket passing between processes

北城余情 提交于 2019-12-21 17:20:14

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/603365/socket-passing-between-processes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!