Class SocketExtensions
Extension methods for Socket class.
Inherited Members
Namespace: UnityFx.Async.Extensions
Assembly: UnityFx.Async-netstandard2.0.dll
Syntax
public static class SocketExtensions
Methods
| Improve this Doc View SourceAcceptAsync(Socket)
Begins an asynchronous operation to accept an incoming connection attempt.
Declaration
public static IAsyncOperation<Socket> AcceptAsync(this Socket socket)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation<Socket> | Returns IAsyncOperation<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
AcceptAsync(Socket, Int32)
Begins an asynchronous operation to accept an incoming connection attempt and receives the first block of data sent by the client application.
Declaration
public static IAsyncOperation<Socket> AcceptAsync(this Socket socket, int receiveSize)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| Int32 | receiveSize | The maximum number of bytes to receive. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation<Socket> | Returns IAsyncOperation<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
AcceptAsync(Socket, Socket, Int32)
Begins an asynchronous operation to accept an incoming connection attempt from a specified socket and receives the first block of data sent by the client application.
Declaration
public static IAsyncOperation<Socket> AcceptAsync(this Socket socket, Socket acceptSocket, int receiveSize)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| Socket | acceptSocket | The accepted Socket object. This value may be null. |
| Int32 | receiveSize | The maximum number of bytes to receive. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation<Socket> | Returns IAsyncOperation<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
ConnectAsync(Socket, EndPoint)
Begins an asynchronous request for a remote host connection.
Declaration
public static IAsyncOperation ConnectAsync(this Socket socket, EndPoint remoteEP)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| EndPoint | remoteEP | An EndPoint that represents the remote host. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation | Returns IAsyncOperation representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| InvalidOperationException | The |
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
ConnectAsync(Socket, IPAddress, Int32)
Begins an asynchronous request for a remote host connection. The host is specified by an IPAddress and a port number.
Declaration
public static IAsyncOperation ConnectAsync(this Socket socket, IPAddress address, int port)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| IPAddress | address | The IPAddress of the remote host. |
| Int32 | port | The port number of the remote host. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation | Returns IAsyncOperation representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| ArgumentOutOfRangeException | Thrown if |
| InvalidOperationException | The |
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
ConnectAsync(Socket, IPAddress[], Int32)
Begins an asynchronous request for a remote host connection. The host is specified by an IPAddress array and a port number.
Declaration
public static IAsyncOperation ConnectAsync(this Socket socket, IPAddress[] addresses, int port)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| IPAddress[] | addresses | At least one IPAddress, designating the remote host. |
| Int32 | port | The port number of the remote host. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation | Returns IAsyncOperation representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| ArgumentOutOfRangeException | Thrown if |
| InvalidOperationException | The |
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
ConnectAsync(Socket, String, Int32)
Begins an asynchronous request for a remote host connection. The host is specified by a host name and a port number.
Declaration
public static IAsyncOperation ConnectAsync(this Socket socket, string host, int port)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| String | host | The name of the remote host. |
| Int32 | port | The port number of the remote host. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation | Returns IAsyncOperation representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| ArgumentOutOfRangeException | Thrown if |
| InvalidOperationException | The |
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
DisconnectAsync(Socket, Boolean)
Begins an asynchronous request to disconnect from a remote endpoint.
Declaration
public static IAsyncOperation DisconnectAsync(this Socket socket, bool reuseSocket)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| Boolean | reuseSocket | true if this socket can be reused after the connection is closed; otherwise, false. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation | Returns IAsyncOperation representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| SocketException | An error occurred when attempting to access the |
| NotSupportedException | The operating system is Windows 2000 or earlier, and this method requires Windows XP. |
| ObjectDisposedException | Thrown if the |
ReceiveAsync(Socket, Byte[], Int32, Int32, SocketFlags)
Begins to asynchronously receive data from a connected Socket.
Declaration
public static IAsyncOperation<int> ReceiveAsync(this Socket socket, byte[] buffer, int offset, int size, SocketFlags socketFlags)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| System.Byte[] | buffer | An array of bytes that is the storage location for the received data. |
| Int32 | offset | The zero-based position in the |
| Int32 | size | The number of bytes to receive. |
| SocketFlags | socketFlags | A bitwise combination of the SocketFlags values. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation<Int32> | Returns IAsyncOperation<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| ArgumentOutOfRangeException | Thrown if |
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
ReceiveAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags)
Begins to asynchronously receive data from a connected Socket.
Declaration
public static IAsyncOperation<int> ReceiveAsync(this Socket socket, IList<ArraySegment<byte>> buffers, SocketFlags socketFlags)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| System.Collections.Generic.IList<System.ArraySegment<System.Byte>> | buffers | An array of bytes that is the storage location for the received data. |
| SocketFlags | socketFlags | A bitwise combination of the SocketFlags values. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation<Int32> | Returns IAsyncOperation<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
SendAsync(Socket, Byte[], Int32, Int32, SocketFlags)
Sends data asynchronously to a connected Socket.
Declaration
public static IAsyncOperation<int> SendAsync(this Socket socket, byte[] buffer, int offset, int size, SocketFlags socketFlags)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| System.Byte[] | buffer | An array of bytes that contains the data to send. |
| Int32 | offset | The zero-based position in the |
| Int32 | size | The number of bytes to send. |
| SocketFlags | socketFlags | A bitwise combination of the SocketFlags values. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation<Int32> | Returns IAsyncOperation<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| ArgumentOutOfRangeException | Thrown if |
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
SendAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags)
Sends data asynchronously to a connected Socket.
Declaration
public static IAsyncOperation<int> SendAsync(this Socket socket, IList<ArraySegment<byte>> buffers, SocketFlags socketFlags)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| System.Collections.Generic.IList<System.ArraySegment<System.Byte>> | buffers | An array of bytes that is the storage location for the received data. |
| SocketFlags | socketFlags | A bitwise combination of the SocketFlags values. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation<Int32> | Returns IAsyncOperation<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| SocketException | An error occurred when attempting to access the |
| ObjectDisposedException | Thrown if the |
SendFileAsync(Socket, String)
Sends the file fileName to a connected Socket object using the UseDefaultWorkerThread flag.
Declaration
public static IAsyncOperation SendFileAsync(this Socket socket, string fileName)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| String | fileName | A string that contains the path and name of the file to send. This parameter can be null. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation | Returns IAsyncOperation representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| FileNotFoundException | The file |
| SocketException | An error occurred when attempting to access the |
| NotSupportedException | The operating system is not Windows NT or later or rhe |
| ObjectDisposedException | Thrown if the |
SendFileAsync(Socket, String, Byte[], Byte[], TransmitFileOptions)
Sends the file fileName to a connected Socket object.
Declaration
public static IAsyncOperation SendFileAsync(this Socket socket, string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | The target socket. |
| String | fileName | A string that contains the path and name of the file to send. This parameter can be null. |
| System.Byte[] | preBuffer | A byte array that contains data to be sent before the file is sent. This parameter can be null. |
| System.Byte[] | postBuffer | A byte array that contains data to be sent after the file is sent. This parameter can be null. |
| TransmitFileOptions | flags | A bitwise combination of TransmitFileOptions values. |
Returns
| Type | Description |
|---|---|
| IAsyncOperation | Returns IAsyncOperation representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| FileNotFoundException | The file |
| SocketException | An error occurred when attempting to access the |
| NotSupportedException | The operating system is not Windows NT or later or rhe |
| ObjectDisposedException | Thrown if the |