System.Net.Sockets.Socket.DuplicateAndClose Method

Duplicates the socket reference for the target process, and closes the socket for this process.

Syntax

[System.MonoLimitation("We do not support passing sockets across processes, we merely allow this API to pass the socket across AppDomains")]
public SocketInformation DuplicateAndClose (int targetProcessId)

Parameters

targetProcessId
The ID of the target process where a duplicate of the socket reference is created.

Returns

The socket reference to be passed to the target process.

Remarks

The target process should use Socket.#ctor(SocketInformation) to create the duplicate socket instance.

If you call the Socket.#ctor(SocketInformation) constructor multiple times with the same byte array as the argument for each call, you will create multiple managed System.Net.Sockets.Socket instances with the same underlying socket. This practice is strongly discouraged.

If the process creating the socket uses asynchronous methods (erload:System.Net.Sockets.Socket.BeginReceive or erload:System.Net.Sockets.Socket.BeginSend), the process must first set the Socket.UseOnlyOverlappedIO property to true; otherwise, the socket is bound to the completion port of the creating process, which may cause an ArgumentNullException to be thrown on the target process.

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0