Socket Class

Definition

Implements the Berkeley sockets interface.

public class Socket : IDisposable
Inheritance
Socket
Implements

Inherited Members

System.Object

Examples

The following code example shows how the Socket class can be used to send data to an HTTP server and receive the response. This example blocks until the entire page is received.

#using <System.dll>

using namespace System;
using namespace System::Text;
using namespace System::IO;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Collections;
Socket^ ConnectSocket( String^ server, int port )
{
   Socket^ s = nullptr;
   IPHostEntry^ hostEntry = nullptr;
   
   // Get host related information.
   hostEntry = Dns::Resolve( server );
   
   // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
   // an exception that occurs when the host IP Address is not compatible with the address family
   // (typical in the IPv6 case).
   IEnumerator^ myEnum = hostEntry->AddressList->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      IPAddress^ address = safe_cast<IPAddress^>(myEnum->Current);
      IPEndPoint^ endPoint = gcnew IPEndPoint( address,port );
      Socket^ tmpS = gcnew Socket( endPoint->AddressFamily,SocketType::Stream,ProtocolType::Tcp );
      tmpS->Connect( endPoint );
      if ( tmpS->Connected )
      {
         s = tmpS;
         break;
      }
      else
      {
         continue;
      }
   }

   return s;
}


// This method requests the home page content for the specified server.
String^ SocketSendReceive( String^ server, int port )
{
   String^ request = String::Concat( "GET / HTTP/1.1\r\nHost: ", server, "\r\nConnection: Close\r\n\r\n" );
   array<Byte>^bytesSent = Encoding::ASCII->GetBytes( request );
   array<Byte>^bytesReceived = gcnew array<Byte>(256);
   
   // Create a socket connection with the specified server and port.
   Socket^ s = ConnectSocket( server, port );
   if ( s == nullptr )
      return ("Connection failed");

   
   // Send request to the server.
   s->Send( bytesSent, bytesSent->Length, static_cast<SocketFlags>(0) );
   
   // Receive the server home page content.
   int bytes = 0;
   String^ strRetPage = String::Concat( "Default HTML page on ", server, ":\r\n" );
   do
   {
      bytes = s->Receive( bytesReceived, bytesReceived->Length, static_cast<SocketFlags>(0) );
      strRetPage = String::Concat( strRetPage, Encoding::ASCII->GetString( bytesReceived, 0, bytes ) );
   }
   while ( bytes > 0 );

   return strRetPage;
}

int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   String^ host;
   int port = 80;
   if ( args->Length == 1 )
      
   // If no server name is passed as argument to this program, 
   // use the current host name as default.
   host = Dns::GetHostName();
   else
      host = args[ 1 ];

   String^ result = SocketSendReceive( host, port );
   Console::WriteLine( result );
}

using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;

public class GetSocket
{
    private static Socket ConnectSocket(string server, int port)
    {
        Socket s = null;
        IPHostEntry hostEntry = null;
        
        // Get host related information.
        hostEntry = Dns.GetHostEntry(server);

        // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
        // an exception that occurs when the host IP Address is not compatible with the address family
        // (typical in the IPv6 case).
        foreach(IPAddress address in hostEntry.AddressList)
        {
            IPEndPoint ipe = new IPEndPoint(address, port);
            Socket tempSocket = 
                new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            tempSocket.Connect(ipe);

            if(tempSocket.Connected)
            {
                s = tempSocket;
                break;
            }
            else
            {
                continue;
            }
        }
        return s;
    }

    // This method requests the home page content for the specified server.
    private static string SocketSendReceive(string server, int port) 
    {
        string request = "GET / HTTP/1.1\r\nHost: " + server + 
            "\r\nConnection: Close\r\n\r\n";
        Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
        Byte[] bytesReceived = new Byte[256];
       
        // Create a socket connection with the specified server and port.
        Socket s = ConnectSocket(server, port);

        if (s == null)
            return ("Connection failed");
      
        // Send request to the server.
        s.Send(bytesSent, bytesSent.Length, 0);  
        
        // Receive the server home page content.
        int bytes = 0;
        string page = "Default HTML page on " + server + ":\r\n";

        // The following will block until te page is transmitted.
        do {
            bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
            page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
        }
        while (bytes > 0);
        
        return page;
    }
    
    public static void Main(string[] args) 
    {
        string host;
        int port = 80;

        if (args.Length == 0)
            // If no server name is passed as argument to this program, 
            // use the current host name as the default.
            host = Dns.GetHostName();
        else
            host = args[0];

        string result = SocketSendReceive(host, port); 
        Console.WriteLine(result);
    }
}

Imports System
Imports System.Text
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports Microsoft.VisualBasic

Public Class GetSocket
   
   Private Shared Function ConnectSocket(server As String, port As Integer) As Socket
      Dim s As Socket = Nothing
      Dim hostEntry As IPHostEntry = Nothing      
     
         ' Get host related information.
        hostEntry = Dns.GetHostEntry(server)
         
         ' Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
         ' an exception that occurs when the host host IP Address is not compatible with the address family
         ' (typical in the IPv6 case).
      Dim address As IPAddress
 
        For Each address In  hostEntry.AddressList
            Dim endPoint As New IPEndPoint(address, port)
            Dim tempSocket As New Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
      
            tempSocket.Connect(endPoint)
            
            If tempSocket.Connected Then
               s = tempSocket
               Exit For
            End If

         Next address
      
      Return s
   End Function 
   
   
   ' This method requests the home page content for the specified server.
   
   Private Shared Function SocketSendReceive(server As String, port As Integer) As String
      'Set up variables and String to write to the server.
      Dim ascii As Encoding = Encoding.ASCII
      Dim request As String = "GET / HTTP/1.1" + ControlChars.Cr + ControlChars.Lf + "Host: " + server + ControlChars.Cr + ControlChars.Lf + "Connection: Close" + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf
      Dim bytesSent As [Byte]() = ascii.GetBytes(request)
      Dim bytesReceived(255) As [Byte]
      
      ' Create a socket connection with the specified server and port.
      Dim s As Socket = ConnectSocket(server, port)
      
      If s Is Nothing Then
         Return "Connection failed"
      End If 
      ' Send request to the server.
      s.Send(bytesSent, bytesSent.Length, 0)
      
      ' Receive the server  home page content.
      Dim bytes As Int32
      
      ' Read the first 256 bytes.
      Dim page as [String] = "Default HTML page on " + server + ":" + ControlChars.Cr + ControlChars.Lf
      
      ' The following will block until the page is transmitted.
      Do
         bytes = s.Receive(bytesReceived, bytesReceived.Length, 0)
            page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes)
      Loop While bytes > 0
      
      Return page
   End Function 
   
   'Entry point which delegates to C-style main Private Function
   Public Overloads Shared Sub Main()
      Main(System.Environment.GetCommandLineArgs())
   End Sub
   
   
   Overloads Private Shared Sub Main(args() As String)
      Dim host As String
      Dim port As Integer = 80
      
      If args.Length = 1 Then
         ' If no server name is passed as argument to this program, 
         ' use the current host name as default.
         host = Dns.GetHostName()
      Else
         host = args(1)
      End If 
      
      Dim result As String = SocketSendReceive(host, port)
      
      Console.WriteLine(result)
   End Sub 'Main
End Class  

Remarks

The Socket class provides a rich set of methods and properties for network communications. The Socket class allows you to perform both synchronous and asynchronous data transfer using any of the communication protocols listed in the ProtocolType enumeration.

The Socket class follows the .NET Framework naming pattern for asynchronous methods. For example, the synchronous Receive method corresponds to the asynchronous BeginReceive and EndReceive methods.

If your application only requires one thread during execution, use the following methods, which are designed for synchronous operation mode.

  • If you are using a connection-oriented protocol such as TCP, your server can listen for connections using the Listen method. The Accept method processes any incoming connection requests and returns a Socket that you can use to communicate data with the remote host. Use this returned Socket to call the Send or Receive method. Call the Bind method prior to calling the Listen method if you want to specify the local IP address and port number. Use a port number of zero if you want the underlying service provider to assign a free port for you. If you want to connect to a listening host, call the Connect method. To communicate data, call the Send or Receive method.

  • If you are using a connectionless protocol such as UDP, you do not need to listen for connections at all. Call the ReceiveFrom method to accept any incoming datagrams. Use the SendTo method to send datagrams to a remote host.

To process communications using separate threads during execution, use the following methods, which are designed for asynchronous operation mode.

If you perform multiple asynchronous operations on a socket, they do not necessarily complete in the order in which they are started.

When you are finished sending and receiving data, use the Shutdown method to disable the Socket. After calling Shutdown, call the Close method to release all resources associated with the Socket.

The Socket class allows you to configure your Socket using the SetSocketOption method. Retrieve these settings using the GetSocketOption method.

Note

If you are writing a relatively simple application and do not require maximum performance, consider using TcpClient, TcpListener, and UdpClient. These classes provide a simpler and more user-friendly interface to Socket communications.

Constructors

Socket(SocketInformation)

Initializes a new instance of the Socket class using the specified value returned from DuplicateAndClose(Int32).

Socket(SocketType, ProtocolType)

Initializes a new instance of the Socket class using the specified socket type and protocol.

Socket(AddressFamily, SocketType, ProtocolType)

Initializes a new instance of the Socket class using the specified address family, socket type and protocol.

Properties

AddressFamily

Gets the address family of the Socket.

Available

Gets the amount of data that has been received from the network and is available to be read.

Blocking

Gets or sets a value that indicates whether the Socket is in blocking mode.

Connected

Gets a value that indicates whether a Socket is connected to a remote host as of the last Send or Receive operation.

DontFragment

Gets or sets a Boolean value that specifies whether the Socket allows Internet Protocol (IP) datagrams to be fragmented.

DualMode

Gets or sets a Boolean value that specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6.

EnableBroadcast

Gets or sets a Boolean value that specifies whether the Socket can send or receive broadcast packets.

ExclusiveAddressUse

Gets or sets a Boolean value that specifies whether the Socket allows only one process to bind to a port.

Handle

Gets the operating system handle for the Socket.

IsBound

Gets a value that indicates whether the Socket is bound to a specific local port.

LingerState

Gets or sets a value that specifies whether the Socket will delay closing a socket in an attempt to send all pending data.

LocalEndPoint

Gets the local endpoint.

MulticastLoopback

Gets or sets a value that specifies whether outgoing multicast packets are delivered to the sending application.

NoDelay

Gets or sets a Boolean value that specifies whether the stream Socket is using the Nagle algorithm.

OSSupportsIPv4

Indicates whether the underlying operating system and network adaptors support Internet Protocol version 4 (IPv4).

OSSupportsIPv6

Indicates whether the underlying operating system and network adaptors support Internet Protocol version 6 (IPv6).

ProtocolType

Gets the protocol type of the Socket.

ReceiveBufferSize

Gets or sets a value that specifies the size of the receive buffer of the Socket.

ReceiveTimeout

Gets or sets a value that specifies the amount of time after which a synchronous Receive call will time out.

RemoteEndPoint

Gets the remote endpoint.

SendBufferSize

Gets or sets a value that specifies the size of the send buffer of the Socket.

SendTimeout

Gets or sets a value that specifies the amount of time after which a synchronous Send call will time out.

SocketType

Gets the type of the Socket.

SupportsIPv4

Gets a value indicating whether IPv4 support is available and enabled on the current host.

SupportsIPv6

Gets a value that indicates whether the Framework supports IPv6 for certain obsolete Dns members.

Ttl

Gets or sets a value that specifies the Time To Live (TTL) value of Internet Protocol (IP) packets sent by the Socket.

UseOnlyOverlappedIO

Specifies whether the socket should only use Overlapped I/O mode.

Methods

Accept()

Creates a new Socket for a newly created connection.

AcceptAsync(SocketAsyncEventArgs)

Begins an asynchronous operation to accept an incoming connection attempt.

BeginAccept(Socket, Int32, AsyncCallback, Object)

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.

BeginAccept(Int32, AsyncCallback, Object)

Begins an asynchronous operation to accept an incoming connection attempt and receives the first block of data sent by the client application.

BeginAccept(AsyncCallback, Object)

Begins an asynchronous operation to accept an incoming connection attempt.

BeginConnect(EndPoint, AsyncCallback, Object)

Begins an asynchronous request for a remote host connection.

BeginConnect(IPAddress, Int32, AsyncCallback, Object)

Begins an asynchronous request for a remote host connection. The host is specified by an IPAddress and a port number.

BeginConnect(IPAddress[], Int32, AsyncCallback, Object)

Begins an asynchronous request for a remote host connection. The host is specified by an IPAddress array and a port number.

BeginConnect(String, Int32, AsyncCallback, Object)

Begins an asynchronous request for a remote host connection. The host is specified by a host name and a port number.

BeginDisconnect(Boolean, AsyncCallback, Object)

Begins an asynchronous request to disconnect from a remote endpoint.

BeginReceive(Byte[], Int32, Int32, SocketFlags, SocketError, AsyncCallback, Object)

Begins to asynchronously receive data from a connected Socket.

BeginReceive(Byte[], Int32, Int32, SocketFlags, AsyncCallback, Object)

Begins to asynchronously receive data from a connected Socket.

BeginReceive(IList<ArraySegment<Byte>>, SocketFlags, AsyncCallback, Object)

Begins to asynchronously receive data from a connected Socket.

BeginReceive(IList<ArraySegment<Byte>>, SocketFlags, SocketError, AsyncCallback, Object)

Begins to asynchronously receive data from a connected Socket.

BeginReceiveFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object)

Begins to asynchronously receive data from a specified network device.

BeginReceiveMessageFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object)

Begins to asynchronously receive the specified number of bytes of data into the specified location of the data buffer, using the specified SocketFlags, and stores the endpoint and packet information..

BeginSend(IList<ArraySegment<Byte>>, SocketFlags, AsyncCallback, Object)

Sends data asynchronously to a connected Socket.

BeginSend(IList<ArraySegment<Byte>>, SocketFlags, SocketError, AsyncCallback, Object)

Sends data asynchronously to a connected Socket.

BeginSend(Byte[], Int32, Int32, SocketFlags, AsyncCallback, Object)

Sends data asynchronously to a connected Socket.

BeginSend(Byte[], Int32, Int32, SocketFlags, SocketError, AsyncCallback, Object)

Sends data asynchronously to a connected Socket.

BeginSendFile(String, AsyncCallback, Object)

Sends the file fileName to a connected Socket object using the UseDefaultWorkerThread flag.

BeginSendFile(String, Byte[], Byte[], TransmitFileOptions, AsyncCallback, Object)

Sends a file and buffers of data asynchronously to a connected Socket object.

BeginSendTo(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object)

Sends data asynchronously to a specific remote host.

Bind(EndPoint)

Associates a Socket with a local endpoint.

CancelConnectAsync(SocketAsyncEventArgs)

Cancels an asynchronous request for a remote host connection.

Close(Int32)

Closes the Socket connection and releases all associated resources with a specified timeout to allow queued data to be sent.

Close()

Closes the Socket connection and releases all associated resources.

Connect(EndPoint)

Establishes a connection to a remote host.

Connect(IPAddress, Int32)

Establishes a connection to a remote host. The host is specified by an IP address and a port number.

Connect(IPAddress[], Int32)

Establishes a connection to a remote host. The host is specified by an array of IP addresses and a port number.

Connect(String, Int32)

Establishes a connection to a remote host. The host is specified by a host name and a port number.

ConnectAsync(SocketAsyncEventArgs)

Begins an asynchronous request for a connection to a remote host.

ConnectAsync(SocketType, ProtocolType, SocketAsyncEventArgs)

Begins an asynchronous request for a connection to a remote host.

Disconnect(Boolean)

Closes the socket connection and allows reuse of the socket.

DisconnectAsync(SocketAsyncEventArgs)

Begins an asynchronous request to disconnect from a remote endpoint.

Dispose()

Releases all resources used by the current instance of the Socket class.

Dispose(Boolean)

Releases the unmanaged resources used by the Socket, and optionally disposes of the managed resources.

DuplicateAndClose(Int32)

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

EndAccept(Byte[], Int32, IAsyncResult)

Asynchronously accepts an incoming connection attempt and creates a new Socket object to handle remote host communication. This method returns a buffer that contains the initial data and the number of bytes transferred.

EndAccept(IAsyncResult)

Asynchronously accepts an incoming connection attempt and creates a new Socket to handle remote host communication.

EndAccept(Byte[], IAsyncResult)

Asynchronously accepts an incoming connection attempt and creates a new Socket object to handle remote host communication. This method returns a buffer that contains the initial data transferred.

EndConnect(IAsyncResult)

Ends a pending asynchronous connection request.

EndDisconnect(IAsyncResult)

Ends a pending asynchronous disconnect request.

EndReceive(IAsyncResult)

Ends a pending asynchronous read.

EndReceive(IAsyncResult, SocketError)

Ends a pending asynchronous read.

EndReceiveFrom(IAsyncResult, EndPoint)

Ends a pending asynchronous read from a specific endpoint.

EndReceiveMessageFrom(IAsyncResult, SocketFlags, EndPoint, IPPacketInformation)

Ends a pending asynchronous read from a specific endpoint. This method also reveals more information about the packet than EndReceiveFrom(IAsyncResult, EndPoint).

EndSend(IAsyncResult)

Ends a pending asynchronous send.

EndSend(IAsyncResult, SocketError)

Ends a pending asynchronous send.

EndSendFile(IAsyncResult)

Ends a pending asynchronous send of a file.

EndSendTo(IAsyncResult)

Ends a pending asynchronous send to a specific location.

Finalize()

Frees resources used by the Socket class.

GetSocketOption(SocketOptionLevel, SocketOptionName, Int32)

Returns the value of the specified Socket option in an array.

GetSocketOption(SocketOptionLevel, SocketOptionName, Byte[])

Returns the specified Socket option setting, represented as a byte array.

GetSocketOption(SocketOptionLevel, SocketOptionName)

Returns the value of a specified Socket option, represented as an object.

IOControl(Int32, Byte[], Byte[])

Sets low-level operating modes for the Socket using numerical control codes.

IOControl(IOControlCode, Byte[], Byte[])

Sets low-level operating modes for the Socket using the IOControlCode enumeration to specify control codes.

Listen(Int32)

Places a Socket in a listening state.

Poll(Int32, SelectMode)

Determines the status of the Socket.

Receive(Byte[], Int32, Int32, SocketFlags, SocketError)

Receives data from a bound Socket into a receive buffer, using the specified SocketFlags.

Receive(Byte[], Int32, Int32, SocketFlags)

Receives the specified number of bytes from a bound Socket into the specified offset position of the receive buffer, using the specified SocketFlags.

Receive(IList<ArraySegment<Byte>>, SocketFlags, SocketError)

Receives data from a bound Socket into the list of receive buffers, using the specified SocketFlags.

Receive(Byte[], Int32, SocketFlags)

Receives the specified number of bytes of data from a bound Socket into a receive buffer, using the specified SocketFlags.

Receive(IList<ArraySegment<Byte>>)

Receives data from a bound Socket into the list of receive buffers.

Receive(Byte[], SocketFlags)

Receives data from a bound Socket into a receive buffer, using the specified SocketFlags.

Receive(Byte[])

Receives data from a bound Socket into a receive buffer.

Receive(IList<ArraySegment<Byte>>, SocketFlags)

Receives data from a bound Socket into the list of receive buffers, using the specified SocketFlags.

ReceiveAsync(SocketAsyncEventArgs)

Begins an asynchronous request to receive data from a connected Socket object.

ReceiveFrom(Byte[], EndPoint)

Receives a datagram into the data buffer and stores the endpoint.

ReceiveFrom(Byte[], SocketFlags, EndPoint)

Receives a datagram into the data buffer, using the specified SocketFlags, and stores the endpoint.

ReceiveFrom(Byte[], Int32, SocketFlags, EndPoint)

Receives the specified number of bytes into the data buffer, using the specified SocketFlags, and stores the endpoint.

ReceiveFrom(Byte[], Int32, Int32, SocketFlags, EndPoint)

Receives the specified number of bytes of data into the specified location of the data buffer, using the specified SocketFlags, and stores the endpoint.

ReceiveFromAsync(SocketAsyncEventArgs)

Begins to asynchronously receive data from a specified network device.

ReceiveMessageFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, IPPacketInformation)

Receives the specified number of bytes of data into the specified location of the data buffer, using the specified SocketFlags, and stores the endpoint and packet information.

ReceiveMessageFromAsync(SocketAsyncEventArgs)

Begins to asynchronously receive the specified number of bytes of data into the specified location in the data buffer, using the specified SocketFlags, and stores the endpoint and packet information.

Select(IList, IList, IList, Int32)

Determines the status of one or more sockets.

Send(Byte[])

Sends data to a connected Socket.

Send(IList<ArraySegment<Byte>>)

Sends the set of buffers in the list to a connected Socket.

Send(Byte[], SocketFlags)

Sends data to a connected Socket using the specified SocketFlags.

Send(IList<ArraySegment<Byte>>, SocketFlags)

Sends the set of buffers in the list to a connected Socket, using the specified SocketFlags.

Send(Byte[], Int32, SocketFlags)

Sends the specified number of bytes of data to a connected Socket, using the specified SocketFlags.

Send(IList<ArraySegment<Byte>>, SocketFlags, SocketError)

Sends the set of buffers in the list to a connected Socket, using the specified SocketFlags.

Send(Byte[], Int32, Int32, SocketFlags)

Sends the specified number of bytes of data to a connected Socket, starting at the specified offset, and using the specified SocketFlags.

Send(Byte[], Int32, Int32, SocketFlags, SocketError)

Sends the specified number of bytes of data to a connected Socket, starting at the specified offset, and using the specified SocketFlags

SendAsync(SocketAsyncEventArgs)

Sends data asynchronously to a connected Socket object.

SendFile(String)

Sends the file fileName to a connected Socket object with the UseDefaultWorkerThread transmit flag.

SendFile(String, Byte[], Byte[], TransmitFileOptions)

Sends the file fileName and buffers of data to a connected Socket object using the specified TransmitFileOptions value.

SendPacketsAsync(SocketAsyncEventArgs)

Sends a collection of files or in memory data buffers asynchronously to a connected Socket object.

SendTo(Byte[], EndPoint)

Sends data to the specified endpoint.

SendTo(Byte[], SocketFlags, EndPoint)

Sends data to a specific endpoint using the specified SocketFlags.

SendTo(Byte[], Int32, SocketFlags, EndPoint)

Sends the specified number of bytes of data to the specified endpoint using the specified SocketFlags.

SendTo(Byte[], Int32, Int32, SocketFlags, EndPoint)

Sends the specified number of bytes of data to the specified endpoint, starting at the specified location in the buffer, and using the specified SocketFlags.

SendToAsync(SocketAsyncEventArgs)

Sends data asynchronously to a specific remote host.

SetIPProtectionLevel(IPProtectionLevel)

Set the IP protection level on a socket.

SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean)

Sets the specified Socket option to the specified Boolean value.

SetSocketOption(SocketOptionLevel, SocketOptionName, Byte[])

Sets the specified Socket option to the specified value, represented as a byte array.

SetSocketOption(SocketOptionLevel, SocketOptionName, Int32)

Sets the specified Socket option to the specified integer value.

SetSocketOption(SocketOptionLevel, SocketOptionName, Object)

Sets the specified Socket option to the specified value, represented as an object.

Shutdown(SocketShutdown)

Disables sends and receives on a Socket.

Extension Methods

AcceptAsync(Socket)
AcceptAsync(Socket, Socket)
ConnectAsync(Socket, EndPoint)
ConnectAsync(Socket, IPAddress, Int32)
ConnectAsync(Socket, IPAddress[], Int32)
ConnectAsync(Socket, String, Int32)
ReceiveAsync(Socket, ArraySegment<Byte>, SocketFlags)
ReceiveAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags)
ReceiveFromAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint)
ReceiveMessageFromAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint)
SendAsync(Socket, ArraySegment<Byte>, SocketFlags)
SendAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags)
SendToAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint)

Thread Safety

Instances of this class are thread safe.