本文介绍了进程之间的套接字传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows中是否可以在进程(地址空间不同)之间传递套接字?

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.

"引入了WSADuplicateSocket函数以启用跨进程的套接字共享" ...

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

更多信息:在Apache的源代码(httpd-2.2.11-win32-src.zip)上使用了带有注释的api WSADuplicateSocket.

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

最近,我发现了有关此问题的出色样本.
在非托管环境中如何进行复制-套接字复制-第1部分
是否可以从非托管进程转移套接字? -套接字复制-第2部分

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

推荐答案

请参见 WSADuplicateSocket .它有效地表明您可以使用最喜欢的进程间通信方案"将WSAPROTOCOL_INFO结构(仅仅是数据!)发送到目标.

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.

有很多IPC方案.我可能将共享内存与 Boost :: interprocess .但是,如果目标具有窗口+消息循环,则可以使用SendMessage.或剪贴板API,就此而言(尽管有些奇怪).该机制由您选择.

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.

这篇关于进程之间的套接字传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!