在不相关的进程之间复制 Windows 个套接字

Duplicate Windows sockets between unrelated processes

我在学习项目中使用 C 和 Winsock2。

我有一些问题希望有人能确认。

假设我有 2 个不相关的进程,进程 A 和进程 B(不使用 CreateProcess)。不相关的意思是它不是 parent 和 child.

1)

是否可以在 Windows 中接受进程 A 中的套接字并将其传递给进程 B(如果它们不相关)?

2)

我想我必须使用 WSADuplicateSocket?但这只适用于相关流程?

希望有人能解释和确认以上..

Is it possible in Windows to Accept a socket in process A and pass it to process B if they are unrelated?

是的,通过 WSADuplicateSocket():

The WSADuplicateSocket function is used to enable socket sharing between processes. A source process calls WSADuplicateSocket to obtain a special WSAPROTOCOL_INFO structure. It uses some interprocess communications (IPC) mechanism to pass the contents of this structure to a target process, which in turn uses it in a call to WSASocket to obtain a descriptor for the duplicated socket. The special WSAPROTOCOL_INFO structure can only be used once by the target process.

I guess i have to use WSADuplicateSocket?

是的。

but that only works for related processes?

没有。它可以在任何 2 个进程之间正常工作,只要进程 A 知道进程 B 的进程 ID,因为这是 WSADuplicateSocket().

的必需参数