Socket Socket Socket Socket Class

定义

实现 Berkeley 套接字接口。Implements the Berkeley sockets interface.

public ref class Socket : IDisposable
public class Socket : IDisposable
type Socket = class
    interface IDisposable
Public Class Socket
Implements IDisposable
继承
SocketSocketSocketSocket
实现

示例

下面的代码示例演示如何Socket使用类将数据发送到 HTTP 服务器并接收响应。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);
   String^ strRetPage = "";
   
   // 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;
   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 );
   
   s->Dispose();

   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];
        string page = "";
        
        // Create a socket connection with the specified server and port.
        using(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;
            page = "Default HTML page on " + server + ":\r\n";

            // 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);
            }
            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.Text
Imports System.IO
Imports System.Net
Imports System.Net.Sockets

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]
      Dim page As String = ""  
      
      ' 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.
      page = "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
End Class  

注解

Socket类提供一组丰富的网络通信方法和属性。The Socket class provides a rich set of methods and properties for network communications. 类允许使用ProtocolType枚举中列出的任何通信协议执行同步和异步数据传输。 SocketThe Socket class allows you to perform both synchronous and asynchronous data transfer using any of the communication protocols listed in the ProtocolType enumeration.

Socket类遵循异步方法的 .NET Framework 命名模式。The Socket class follows the .NET Framework naming pattern for asynchronous methods. 例如,同步Receive方法对应于异步BeginReceiveEndReceive方法。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.

  • 如果使用面向连接的协议(例如 TCP),则服务器可以使用Listen方法侦听连接。If you are using a connection-oriented protocol such as TCP, your server can listen for connections using the Listen method. 方法处理任何传入的Socket连接请求,并返回可用于与远程主机通信数据的。 AcceptThe Accept method processes any incoming connection requests and returns a Socket that you can use to communicate data with the remote host. 使用此返回SocketSend调用或Receive方法。Use this returned Socket to call the Send or Receive method. 如果要指定本地 IP 地址和Listen端口号,请在调用方法之前调用方法。BindCall 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. 如果要连接到侦听主机,请调用Connect方法。If you want to connect to a listening host, call the Connect method. 若要传递数据,请Send调用Receive或方法。To communicate data, call the Send or Receive method.

  • 如果使用的是无连接协议(如 UDP),则无需侦听连接。If you are using a connectionless protocol such as UDP, you do not need to listen for connections at all. ReceiveFrom调用方法以接受任何传入的数据报。Call the ReceiveFrom method to accept any incoming datagrams. SendTo使用方法将数据报发送到远程主机。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.

完成发送和接收数据的操作后,请使用Shutdown方法Socket禁用。When you are finished sending and receiving data, use the Shutdown method to disable the Socket. 调用Shutdown后, Close调用方法以释放与关联的Socket所有资源。After calling Shutdown, call the Close method to release all resources associated with the Socket.

通过类,可以使用SetSocketOption方法来配置。 Socket SocketThe Socket class allows you to configure your Socket using the SetSocketOption method. 使用GetSocketOption方法检索这些设置。Retrieve these settings using the GetSocketOption method.

备注

如果你正在编写一个相对简单的应用程序,并且不需要最佳性能, TcpClientTcpListener考虑使用UdpClient、和。If you are writing a relatively simple application and do not require maximum performance, consider using TcpClient, TcpListener, and UdpClient. 这些类为Socket通信提供更简单、更易于用户使用的界面。These classes provide a simpler and more user-friendly interface to Socket communications.

构造函数

Socket(AddressFamily, SocketType, ProtocolType) Socket(AddressFamily, SocketType, ProtocolType) Socket(AddressFamily, SocketType, ProtocolType) Socket(AddressFamily, SocketType, ProtocolType)

使用指定的地址族、套接字类型和协议初始化 Socket 类的新实例。Initializes a new instance of the Socket class using the specified address family, socket type and protocol.

Socket(SocketInformation) Socket(SocketInformation) Socket(SocketInformation) Socket(SocketInformation)

使用 Socket 返回的指定的值初始化 DuplicateAndClose(Int32) 类的新实例。Initializes a new instance of the Socket class using the specified value returned from DuplicateAndClose(Int32).

Socket(SocketType, ProtocolType) Socket(SocketType, ProtocolType) Socket(SocketType, ProtocolType) Socket(SocketType, ProtocolType)

使用指定的地址族、套接字类型和协议初始化 Socket 类的新实例。Initializes a new instance of the Socket class using the specified socket type and protocol.

属性

AddressFamily AddressFamily AddressFamily AddressFamily

获取 Socket 的地址族。Gets the address family of the Socket.

Available Available Available Available

获取已经从网络接收且可供读取的数据量。Gets the amount of data that has been received from the network and is available to be read.

Blocking Blocking Blocking Blocking

获取或设置一个值,该值指示 Socket 是否处于阻止模式。Gets or sets a value that indicates whether the Socket is in blocking mode.

Connected Connected Connected Connected

获取一个值,该值指示 Socket 是在上次 Send 还是 Receive 操作时连接到远程主机。Gets a value that indicates whether a Socket is connected to a remote host as of the last Send or Receive operation.

DontFragment DontFragment DontFragment DontFragment

获取或设置 Boolean 值,该值指定 Socket 是否允许将 Internet 协议 (IP) 数据报分段。Gets or sets a Boolean value that specifies whether the Socket allows Internet Protocol (IP) datagrams to be fragmented.

DualMode DualMode DualMode DualMode

获取或设置一个 Boolean 值,该值指定 Socket 是否是用于 IPv4 和 IPv6 的双模式套接字。Gets or sets a Boolean value that specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6.

EnableBroadcast EnableBroadcast EnableBroadcast EnableBroadcast

获取或设置一个 Boolean 值,该值指定 Socket 是否可以发送或接收广播数据包。Gets or sets a Boolean value that specifies whether the Socket can send or receive broadcast packets.

ExclusiveAddressUse ExclusiveAddressUse ExclusiveAddressUse ExclusiveAddressUse

获取或设置 Boolean 值,该值指定 Socket 是否仅允许一个进程绑定到端口。Gets or sets a Boolean value that specifies whether the Socket allows only one process to bind to a port.

Handle Handle Handle Handle

获取 Socket 的操作系统句柄。Gets the operating system handle for the Socket.

IsBound IsBound IsBound IsBound

获取一个值,该值指示 Socket 是否绑定到特定本地端口。Gets a value that indicates whether the Socket is bound to a specific local port.

LingerState LingerState LingerState LingerState

获取或设置一个值,该值指定 Socket 在尝试发送所有挂起数据时是否延迟关闭套接字。Gets or sets a value that specifies whether the Socket will delay closing a socket in an attempt to send all pending data.

LocalEndPoint LocalEndPoint LocalEndPoint LocalEndPoint

获取本地终结点。Gets the local endpoint.

MulticastLoopback MulticastLoopback MulticastLoopback MulticastLoopback

获取或设置一个值,该值指定传出的多路广播数据包是否传递到发送应用程序。Gets or sets a value that specifies whether outgoing multicast packets are delivered to the sending application.

NoDelay NoDelay NoDelay NoDelay

获取或设置 Boolean 值,该值指定流 Socket 是否正在使用 Nagle 算法。Gets or sets a Boolean value that specifies whether the stream Socket is using the Nagle algorithm.

OSSupportsIPv4 OSSupportsIPv4 OSSupportsIPv4 OSSupportsIPv4

指示基础操作系统和网络适配器是否支持 Internet 协议第 4 版 (IPv4)。Indicates whether the underlying operating system and network adaptors support Internet Protocol version 4 (IPv4).

OSSupportsIPv6 OSSupportsIPv6 OSSupportsIPv6 OSSupportsIPv6

指示基础操作系统和网络适配器是否支持 Internet 协议第 6 版 (IPv6)。Indicates whether the underlying operating system and network adaptors support Internet Protocol version 6 (IPv6).

ProtocolType ProtocolType ProtocolType ProtocolType

获取 Socket 的协议类型。Gets the protocol type of the Socket.

ReceiveBufferSize ReceiveBufferSize ReceiveBufferSize ReceiveBufferSize

获取或设置一个值,它指定 Socket 接收缓冲区的大小。Gets or sets a value that specifies the size of the receive buffer of the Socket.

ReceiveTimeout ReceiveTimeout ReceiveTimeout ReceiveTimeout

获取或设置一个值,该值指定之后同步 Receive 调用将超时的时间长度。Gets or sets a value that specifies the amount of time after which a synchronous Receive call will time out.

RemoteEndPoint RemoteEndPoint RemoteEndPoint RemoteEndPoint

获取远程终结点。Gets the remote endpoint.

SafeHandle SafeHandle SafeHandle SafeHandle

获取一个 SafeSocketHandle,它表示当前 Socket 对象封装的套接字句柄。Gets a SafeSocketHandle that represents the socket handle that the current Socket object encapsulates.

SendBufferSize SendBufferSize SendBufferSize SendBufferSize

获取或设置一个值,该值指定 Socket 发送缓冲区的大小。Gets or sets a value that specifies the size of the send buffer of the Socket.

SendTimeout SendTimeout SendTimeout SendTimeout

获取或设置一个值,该值指定之后同步 Send 调用将超时的时间长度。Gets or sets a value that specifies the amount of time after which a synchronous Send call will time out.

SocketType SocketType SocketType SocketType

获取 Socket 的类型。Gets the type of the Socket.

SupportsIPv4 SupportsIPv4 SupportsIPv4 SupportsIPv4

获取一个值,该值指示在当前主机上 IPv4 支持是否可用并且已启用。Gets a value indicating whether IPv4 support is available and enabled on the current host.

SupportsIPv6 SupportsIPv6 SupportsIPv6 SupportsIPv6

获取一个值,该值指示 Framework 对某些已过时的 Dns 成员是否支持 IPv6。Gets a value that indicates whether the Framework supports IPv6 for certain obsolete Dns members.

Ttl Ttl Ttl Ttl

获取或设置一个值,指定 Socket 发送的 Internet 协议 (IP) 数据包的生存时间 (TTL) 值。Gets or sets a value that specifies the Time To Live (TTL) value of Internet Protocol (IP) packets sent by the Socket.

UseOnlyOverlappedIO UseOnlyOverlappedIO UseOnlyOverlappedIO UseOnlyOverlappedIO

指定套接字是否应仅使用重叠 I/O 模式。Specifies whether the socket should only use Overlapped I/O mode.

方法

Accept() Accept() Accept() Accept()

为新建连接创建新的 SocketCreates a new Socket for a newly created connection.

AcceptAsync(SocketAsyncEventArgs) AcceptAsync(SocketAsyncEventArgs) AcceptAsync(SocketAsyncEventArgs) AcceptAsync(SocketAsyncEventArgs)

开始一个异步操作来接受一个传入的连接尝试。Begins an asynchronous operation to accept an incoming connection attempt.

BeginAccept(AsyncCallback, Object) BeginAccept(AsyncCallback, Object) BeginAccept(AsyncCallback, Object) BeginAccept(AsyncCallback, Object)

开始一个异步操作来接受一个传入的连接尝试。Begins an asynchronous operation to accept an incoming connection attempt.

BeginAccept(Int32, AsyncCallback, Object) BeginAccept(Int32, AsyncCallback, Object) BeginAccept(Int32, AsyncCallback, Object) 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(Socket, Int32, AsyncCallback, Object) BeginAccept(Socket, Int32, AsyncCallback, Object) BeginAccept(Socket, Int32, AsyncCallback, Object) 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.

BeginConnect(EndPoint, AsyncCallback, Object) BeginConnect(EndPoint, AsyncCallback, Object) BeginConnect(EndPoint, AsyncCallback, Object) BeginConnect(EndPoint, AsyncCallback, Object)

开始一个对远程主机连接的异步请求。Begins an asynchronous request for a remote host connection.

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

开始一个对远程主机连接的异步请求。Begins an asynchronous request for a remote host connection. 主机由 IPAddress 和端口号指定。The host is specified by an IPAddress and a port number.

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

开始一个对远程主机连接的异步请求。Begins an asynchronous request for a remote host connection. 主机由 IPAddress 数组和端口号指定。The host is specified by an IPAddress array and a port number.

BeginConnect(String, Int32, AsyncCallback, Object) BeginConnect(String, Int32, AsyncCallback, Object) BeginConnect(String, Int32, AsyncCallback, Object) 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) BeginDisconnect(Boolean, AsyncCallback, Object) BeginDisconnect(Boolean, AsyncCallback, Object) BeginDisconnect(Boolean, AsyncCallback, Object)

开始异步请求从远程终结点断开连接。Begins an asynchronous request to disconnect from a remote endpoint.

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

开始从连接的 Socket 中异步接收数据。Begins to asynchronously receive data from a connected Socket.

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

开始从连接的 Socket 中异步接收数据。Begins to asynchronously receive data from a connected Socket.

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

开始从连接的 Socket 中异步接收数据。Begins to asynchronously receive data from a connected Socket.

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

开始从连接的 Socket 中异步接收数据。Begins to asynchronously receive data from a connected Socket.

BeginReceiveFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object) BeginReceiveFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object) BeginReceiveFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object) 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) BeginReceiveMessageFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object) BeginReceiveMessageFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object) BeginReceiveMessageFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object)

开始使用指定的 SocketFlags 将指定字节数的数据异步接收到数据缓冲区的指定位置,然后存储终结点和数据包信息。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(Byte[], Int32, Int32, SocketFlags, AsyncCallback, Object) BeginSend(Byte[], Int32, Int32, SocketFlags, AsyncCallback, Object) BeginSend(Byte[], Int32, Int32, SocketFlags, AsyncCallback, Object) BeginSend(Byte[], Int32, Int32, SocketFlags, AsyncCallback, Object)

将数据异步发送到连接的 SocketSends data asynchronously to a connected Socket.

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

将数据异步发送到连接的 SocketSends data asynchronously to a connected Socket.

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

将数据异步发送到连接的 SocketSends data asynchronously to a connected Socket.

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

将数据异步发送到连接的 SocketSends data asynchronously to a connected Socket.

BeginSendFile(String, AsyncCallback, Object) BeginSendFile(String, AsyncCallback, Object) BeginSendFile(String, AsyncCallback, Object) BeginSendFile(String, AsyncCallback, Object)

使用 Socket 标志,将文件 fileName 发送到连接的 UseDefaultWorkerThread 对象。Sends the file fileName to a connected Socket object using the UseDefaultWorkerThread flag.

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

将文件和数据缓冲区异步发送到连接的 Socket 对象。Sends a file and buffers of data asynchronously to a connected Socket object.

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

以异步方式将数据发送到特定远程主机。Sends data asynchronously to a specific remote host.

Bind(EndPoint) Bind(EndPoint) Bind(EndPoint) Bind(EndPoint)

使 Socket 与一个本地终结点相关联。Associates a Socket with a local endpoint.

CancelConnectAsync(SocketAsyncEventArgs) CancelConnectAsync(SocketAsyncEventArgs) CancelConnectAsync(SocketAsyncEventArgs) CancelConnectAsync(SocketAsyncEventArgs)

取消一个对远程主机连接的异步请求。Cancels an asynchronous request for a remote host connection.

Close() Close() Close() Close()

关闭 Socket 连接并释放所有关联的资源。Closes the Socket connection and releases all associated resources.

Close(Int32) Close(Int32) Close(Int32) Close(Int32)

关闭 Socket 连接并释放所有与指定超时关联的资源,以允许要发送的数据排队。Closes the Socket connection and releases all associated resources with a specified timeout to allow queued data to be sent.

Connect(EndPoint) Connect(EndPoint) Connect(EndPoint) Connect(EndPoint)

与远程主机建立连接。Establishes a connection to a remote host.

Connect(IPAddress, Int32) Connect(IPAddress, Int32) Connect(IPAddress, Int32) Connect(IPAddress, Int32)

与远程主机建立连接。Establishes a connection to a remote host. 主机由 IP 地址和端口号指定。The host is specified by an IP address and a port number.

Connect(IPAddress[], Int32) Connect(IPAddress[], Int32) Connect(IPAddress[], Int32) Connect(IPAddress[], Int32)

与远程主机建立连接。Establishes a connection to a remote host. 主机由 IP 地址数组和端口号指定。The host is specified by an array of IP addresses and a port number.

Connect(String, Int32) Connect(String, Int32) Connect(String, Int32) Connect(String, Int32)

与远程主机建立连接。Establishes a connection to a remote host. 主机由主机名和端口号指定。The host is specified by a host name and a port number.

ConnectAsync(SocketAsyncEventArgs) ConnectAsync(SocketAsyncEventArgs) ConnectAsync(SocketAsyncEventArgs) ConnectAsync(SocketAsyncEventArgs)

开始一个对远程主机连接的异步请求。Begins an asynchronous request for a connection to a remote host.

ConnectAsync(SocketType, ProtocolType, SocketAsyncEventArgs) ConnectAsync(SocketType, ProtocolType, SocketAsyncEventArgs) ConnectAsync(SocketType, ProtocolType, SocketAsyncEventArgs) ConnectAsync(SocketType, ProtocolType, SocketAsyncEventArgs)

开始一个对远程主机连接的异步请求。Begins an asynchronous request for a connection to a remote host.

Disconnect(Boolean) Disconnect(Boolean) Disconnect(Boolean) Disconnect(Boolean)

关闭套接字连接并允许重用套接字。Closes the socket connection and allows reuse of the socket.

DisconnectAsync(SocketAsyncEventArgs) DisconnectAsync(SocketAsyncEventArgs) DisconnectAsync(SocketAsyncEventArgs) DisconnectAsync(SocketAsyncEventArgs)

开始异步请求从远程终结点断开连接。Begins an asynchronous request to disconnect from a remote endpoint.

Dispose() Dispose() Dispose() Dispose()

释放 Socket 类的当前实例所使用的所有资源。Releases all resources used by the current instance of the Socket class.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 Socket 使用的非托管资源,并可根据需要释放托管资源。Releases the unmanaged resources used by the Socket, and optionally disposes of the managed resources.

DuplicateAndClose(Int32) DuplicateAndClose(Int32) DuplicateAndClose(Int32) DuplicateAndClose(Int32)

重复目标进程的套接字引用,并关闭此进程的套接字。Duplicates the socket reference for the target process, and closes the socket for this process.

EndAccept(Byte[], IAsyncResult) EndAccept(Byte[], IAsyncResult) EndAccept(Byte[], IAsyncResult) EndAccept(Byte[], IAsyncResult)

异步接受传入的连接尝试,并创建新的 Socket 对象来处理远程主机通信。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.

EndAccept(Byte[], Int32, IAsyncResult) EndAccept(Byte[], Int32, IAsyncResult) EndAccept(Byte[], Int32, IAsyncResult) EndAccept(Byte[], Int32, IAsyncResult)

异步接受传入的连接尝试,并创建新的 Socket 对象来处理远程主机通信。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) EndAccept(IAsyncResult) EndAccept(IAsyncResult) EndAccept(IAsyncResult)

异步接受传入的连接尝试,并创建新的 Socket 来处理远程主机通信。Asynchronously accepts an incoming connection attempt and creates a new Socket to handle remote host communication.

EndConnect(IAsyncResult) EndConnect(IAsyncResult) EndConnect(IAsyncResult) EndConnect(IAsyncResult)

结束挂起的异步连接请求。Ends a pending asynchronous connection request.

EndDisconnect(IAsyncResult) EndDisconnect(IAsyncResult) EndDisconnect(IAsyncResult) EndDisconnect(IAsyncResult)

结束挂起的异步断开连接请求。Ends a pending asynchronous disconnect request.

EndReceive(IAsyncResult) EndReceive(IAsyncResult) EndReceive(IAsyncResult) EndReceive(IAsyncResult)

结束挂起的异步读取。Ends a pending asynchronous read.

EndReceive(IAsyncResult, SocketError) EndReceive(IAsyncResult, SocketError) EndReceive(IAsyncResult, SocketError) EndReceive(IAsyncResult, SocketError)

结束挂起的异步读取。Ends a pending asynchronous read.

EndReceiveFrom(IAsyncResult, EndPoint) EndReceiveFrom(IAsyncResult, EndPoint) EndReceiveFrom(IAsyncResult, EndPoint) EndReceiveFrom(IAsyncResult, EndPoint)

结束挂起的、从特定终结点进行异步读取。Ends a pending asynchronous read from a specific endpoint.

EndReceiveMessageFrom(IAsyncResult, SocketFlags, EndPoint, IPPacketInformation) EndReceiveMessageFrom(IAsyncResult, SocketFlags, EndPoint, IPPacketInformation) EndReceiveMessageFrom(IAsyncResult, SocketFlags, EndPoint, IPPacketInformation) EndReceiveMessageFrom(IAsyncResult, SocketFlags, EndPoint, IPPacketInformation)

结束挂起的、从特定终结点进行异步读取。Ends a pending asynchronous read from a specific endpoint. 此方法还显示有关数据包而不是 EndReceiveFrom(IAsyncResult, EndPoint) 的更多信息。This method also reveals more information about the packet than EndReceiveFrom(IAsyncResult, EndPoint).

EndSend(IAsyncResult) EndSend(IAsyncResult) EndSend(IAsyncResult) EndSend(IAsyncResult)

结束挂起的异步发送。Ends a pending asynchronous send.

EndSend(IAsyncResult, SocketError) EndSend(IAsyncResult, SocketError) EndSend(IAsyncResult, SocketError) EndSend(IAsyncResult, SocketError)

结束挂起的异步发送。Ends a pending asynchronous send.

EndSendFile(IAsyncResult) EndSendFile(IAsyncResult) EndSendFile(IAsyncResult) EndSendFile(IAsyncResult)

结束文件的挂起异步发送。Ends a pending asynchronous send of a file.

EndSendTo(IAsyncResult) EndSendTo(IAsyncResult) EndSendTo(IAsyncResult) EndSendTo(IAsyncResult)

结束挂起的、向指定位置进行的异步发送。Ends a pending asynchronous send to a specific location.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

释放 Socket 类使用的资源。Frees resources used by the Socket class.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回 Socket 实例的哈希值。Returns a hash value for a Socket instance.

GetSocketOption(SocketOptionLevel, SocketOptionName) GetSocketOption(SocketOptionLevel, SocketOptionName) GetSocketOption(SocketOptionLevel, SocketOptionName) GetSocketOption(SocketOptionLevel, SocketOptionName)

返回指定的 Socket 选项的值,表示为一个对象。Returns the value of a specified Socket option, represented as an object.

GetSocketOption(SocketOptionLevel, SocketOptionName, Byte[]) GetSocketOption(SocketOptionLevel, SocketOptionName, Byte[]) GetSocketOption(SocketOptionLevel, SocketOptionName, Byte[]) GetSocketOption(SocketOptionLevel, SocketOptionName, Byte[])

返回指定的 Socket 选项设置,表示为字节数组。Returns the specified Socket option setting, represented as a byte array.

GetSocketOption(SocketOptionLevel, SocketOptionName, Int32) GetSocketOption(SocketOptionLevel, SocketOptionName, Int32) GetSocketOption(SocketOptionLevel, SocketOptionName, Int32) GetSocketOption(SocketOptionLevel, SocketOptionName, Int32)

返回数组中指定的 Socket 选项的值。Returns the value of the specified Socket option in an array.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IOControl(Int32, Byte[], Byte[]) IOControl(Int32, Byte[], Byte[]) IOControl(Int32, Byte[], Byte[]) IOControl(Int32, Byte[], Byte[])

使用数字控制代码,为 Socket 设置低级操作模式。Sets low-level operating modes for the Socket using numerical control codes.

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

使用 Socket 枚举指定控制代码,为 IOControlCode 设置低级操作模式。Sets low-level operating modes for the Socket using the IOControlCode enumeration to specify control codes.

Listen(Int32) Listen(Int32) Listen(Int32) Listen(Int32)

Socket 置于侦听状态。Places a Socket in a listening state.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Poll(Int32, SelectMode) Poll(Int32, SelectMode) Poll(Int32, SelectMode) Poll(Int32, SelectMode)

确定 Socket 的状态。Determines the status of the Socket.

Receive(Byte[]) Receive(Byte[]) Receive(Byte[]) Receive(Byte[])

从绑定的 Socket 套接字接收数据,将数据存入接收缓冲区。Receives data from a bound Socket into a receive buffer.

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

使用指定的 Socket,从绑定的 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(Byte[], Int32, Int32, SocketFlags, SocketError) Receive(Byte[], Int32, Int32, SocketFlags, SocketError) Receive(Byte[], Int32, Int32, SocketFlags, SocketError) Receive(Byte[], Int32, Int32, SocketFlags, SocketError)

使用指定的 Socket,从绑定的 SocketFlags 接收数据,将数据存入接收缓冲区。Receives data from a bound Socket into a receive buffer, using the specified SocketFlags.

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

使用指定的 Socket,从绑定的 SocketFlags 接收指定字节数的数据,并将数据存入接收缓冲区。Receives the specified number of bytes of data from a bound Socket into a receive buffer, using the specified SocketFlags.

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

使用指定的 Socket,从绑定的 SocketFlags 接收数据,将数据存入接收缓冲区。Receives data from a bound Socket into a receive buffer, using the specified SocketFlags.

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

从绑定的 Socket 接收数据,将数据存入接收缓冲区列表中。Receives data from a bound Socket into the list of receive buffers.

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

使用指定的 Socket,从绑定的 SocketFlags 接收数据,将数据存入接收缓冲区列表中。Receives data from a bound Socket into the list of receive buffers, using the specified SocketFlags.

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

使用指定的 Socket,从绑定的 SocketFlags 接收数据,将数据存入接收缓冲区列表中。Receives data from a bound Socket into the list of receive buffers, using the specified SocketFlags.

Receive(Span<Byte>) Receive(Span<Byte>) Receive(Span<Byte>) Receive(Span<Byte>)
Receive(Span<Byte>, SocketFlags) Receive(Span<Byte>, SocketFlags) Receive(Span<Byte>, SocketFlags) Receive(Span<Byte>, SocketFlags)
Receive(Span<Byte>, SocketFlags, SocketError) Receive(Span<Byte>, SocketFlags, SocketError) Receive(Span<Byte>, SocketFlags, SocketError) Receive(Span<Byte>, SocketFlags, SocketError)
ReceiveAsync(SocketAsyncEventArgs) ReceiveAsync(SocketAsyncEventArgs) ReceiveAsync(SocketAsyncEventArgs) ReceiveAsync(SocketAsyncEventArgs)

开始一个异步请求以便从连接的 Socket 对象中接收数据。Begins an asynchronous request to receive data from a connected Socket object.

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

将数据报接收到数据缓冲区并存储终结点。Receives a datagram into the data buffer and stores the endpoint.

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

使用指定的 SocketFlags 将指定的数据字节数接收到数据缓冲区的指定位置,并存储终结点。Receives the specified number of bytes of data into the specified location of the data buffer, using the specified SocketFlags, and stores the endpoint.

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

使用指定的 SocketFlags 将指定的字节数接收到数据缓冲区并存储终结点。Receives the specified number of bytes into the data buffer, using the specified SocketFlags, and stores the endpoint.

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

使用指定的 SocketFlags 将数据报接收到数据缓冲区并存储终结点。Receives a datagram into the data buffer, using the specified SocketFlags, and stores the endpoint.

ReceiveFromAsync(SocketAsyncEventArgs) ReceiveFromAsync(SocketAsyncEventArgs) ReceiveFromAsync(SocketAsyncEventArgs) ReceiveFromAsync(SocketAsyncEventArgs)

开始从指定网络设备中异步接收数据。Begins to asynchronously receive data from a specified network device.

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

使用指定的 SocketFlags 将指定字节数的数据接收到指定的数据缓冲区位置,并存储终结点和数据包信息。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) ReceiveMessageFromAsync(SocketAsyncEventArgs) ReceiveMessageFromAsync(SocketAsyncEventArgs) ReceiveMessageFromAsync(SocketAsyncEventArgs)

开始使用指定的 SocketFlags 将指定字节数的数据异步接收到数据缓冲区的指定位置,并存储终结点和数据包信息。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) Select(IList, IList, IList, Int32) Select(IList, IList, IList, Int32) Select(IList, IList, IList, Int32)

确定一个或多个套接字的状态。Determines the status of one or more sockets.

Send(Byte[]) Send(Byte[]) Send(Byte[]) Send(Byte[])

将数据发送到连接的 SocketSends data to a connected Socket.

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

从指定偏移量开始,使用指定 SocketFlags,将指定的数据字节数发送到已连接的 SocketSends 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) Send(Byte[], Int32, Int32, SocketFlags, SocketError) Send(Byte[], Int32, Int32, SocketFlags, SocketError) Send(Byte[], Int32, Int32, SocketFlags, SocketError)

从指定的偏移量开始使用指定的 Socket 将指定字节数的数据发送到连接的 SocketFlagsSends the specified number of bytes of data to a connected Socket, starting at the specified offset, and using the specified SocketFlags

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

使用指定的 Socket,将指定字节数的数据发送到已连接的 SocketFlagsSends the specified number of bytes of data to a connected Socket, using the specified SocketFlags.

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

使用指定的 Socket 将数据发送到连接的 SocketFlagsSends data to a connected Socket using the specified SocketFlags.

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

将列表中的一组缓冲区发送到连接的 SocketSends the set of buffers in the list to a connected Socket.

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

使用指定的 Socket,将列表中的一组缓冲区发送到连接的 SocketFlagsSends the set of buffers in the list to a connected Socket, using the specified SocketFlags.

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

使用指定的 Socket,将列表中的一组缓冲区发送到连接的 SocketFlagsSends the set of buffers in the list to a connected Socket, using the specified SocketFlags.

Send(ReadOnlySpan<Byte>) Send(ReadOnlySpan<Byte>) Send(ReadOnlySpan<Byte>) Send(ReadOnlySpan<Byte>)
Send(ReadOnlySpan<Byte>, SocketFlags) Send(ReadOnlySpan<Byte>, SocketFlags) Send(ReadOnlySpan<Byte>, SocketFlags) Send(ReadOnlySpan<Byte>, SocketFlags)
Send(ReadOnlySpan<Byte>, SocketFlags, SocketError) Send(ReadOnlySpan<Byte>, SocketFlags, SocketError) Send(ReadOnlySpan<Byte>, SocketFlags, SocketError) Send(ReadOnlySpan<Byte>, SocketFlags, SocketError)
SendAsync(SocketAsyncEventArgs) SendAsync(SocketAsyncEventArgs) SendAsync(SocketAsyncEventArgs) SendAsync(SocketAsyncEventArgs)

将数据异步发送到连接的 Socket 对象。Sends data asynchronously to a connected Socket object.

SendFile(String) SendFile(String) SendFile(String) SendFile(String)

使用 Socket 传输标志,将文件 fileName 发送到连接的 UseDefaultWorkerThread 对象。Sends the file fileName to a connected Socket object with the UseDefaultWorkerThread transmit flag.

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

通过指定的 TransmitFileOptions 值,将文件 fileName 和数据缓冲区发送到连接的 Socket 对象。Sends the file fileName and buffers of data to a connected Socket object using the specified TransmitFileOptions value.

SendPacketsAsync(SocketAsyncEventArgs) SendPacketsAsync(SocketAsyncEventArgs) SendPacketsAsync(SocketAsyncEventArgs) SendPacketsAsync(SocketAsyncEventArgs)

将文件集合或者内存中的数据缓冲区以异步方法发送给连接的 Socket 对象。Sends a collection of files or in memory data buffers asynchronously to a connected Socket object.

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

将数据发送到指定的终结点。Sends data to the specified endpoint.

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

使用指定的 SocketFlags,将指定字节数的数据发送到指定终结点(从缓冲区中的指定位置开始)。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.

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

使用指定的 SocketFlags,将指定字节数的数据发送到指定的终结点。Sends the specified number of bytes of data to the specified endpoint using the specified SocketFlags.

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

使用指定的 SocketFlags,将数据发送到特定的终结点。Sends data to a specific endpoint using the specified SocketFlags.

SendToAsync(SocketAsyncEventArgs) SendToAsync(SocketAsyncEventArgs) SendToAsync(SocketAsyncEventArgs) SendToAsync(SocketAsyncEventArgs)

以异步方式将数据发送到特定远程主机。Sends data asynchronously to a specific remote host.

SetIPProtectionLevel(IPProtectionLevel) SetIPProtectionLevel(IPProtectionLevel) SetIPProtectionLevel(IPProtectionLevel) SetIPProtectionLevel(IPProtectionLevel)

设置套接字的 IP 保护级别。Set the IP protection level on a socket.

SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean) SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean) SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean) SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean)

将指定的 Socket 选项设置为指定的 Boolean 值。Sets the specified Socket option to the specified Boolean value.

SetSocketOption(SocketOptionLevel, SocketOptionName, Byte[]) SetSocketOption(SocketOptionLevel, SocketOptionName, Byte[]) SetSocketOption(SocketOptionLevel, SocketOptionName, Byte[]) SetSocketOption(SocketOptionLevel, SocketOptionName, Byte[])

将指定的 Socket 选项设置为指定的值,表示为字节数组。Sets the specified Socket option to the specified value, represented as a byte array.

SetSocketOption(SocketOptionLevel, SocketOptionName, Int32) SetSocketOption(SocketOptionLevel, SocketOptionName, Int32) SetSocketOption(SocketOptionLevel, SocketOptionName, Int32) SetSocketOption(SocketOptionLevel, SocketOptionName, Int32)

将指定的 Socket 选项设置为指定的整数值。Sets the specified Socket option to the specified integer value.

SetSocketOption(SocketOptionLevel, SocketOptionName, Object) SetSocketOption(SocketOptionLevel, SocketOptionName, Object) SetSocketOption(SocketOptionLevel, SocketOptionName, Object) SetSocketOption(SocketOptionLevel, SocketOptionName, Object)

将指定的 Socket 选项设置为指定值,表示为对象。Sets the specified Socket option to the specified value, represented as an object.

Shutdown(SocketShutdown) Shutdown(SocketShutdown) Shutdown(SocketShutdown) Shutdown(SocketShutdown)

禁用某 Socket 上的发送和接收。Disables sends and receives on a Socket.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

释放由 Socket 使用的所有资源。Releases all resources used by the Socket.

扩展方法

AcceptAsync(Socket) AcceptAsync(Socket) AcceptAsync(Socket) AcceptAsync(Socket)

执行异步操作,接受套接字上的传入连接尝试。Performs an asynchronous operation on to accept an incoming connection attempt on the socket.

AcceptAsync(Socket, Socket) AcceptAsync(Socket, Socket) AcceptAsync(Socket, Socket) AcceptAsync(Socket, Socket)

执行异步操作,接受套接字上的传入连接尝试。Performs an asynchronous operation on to accept an incoming connection attempt on the socket.

ConnectAsync(Socket, EndPoint) ConnectAsync(Socket, EndPoint) ConnectAsync(Socket, EndPoint) ConnectAsync(Socket, EndPoint)

与远程主机建立连接。Establishes a connection to a remote host.

ConnectAsync(Socket, IPAddress, Int32) ConnectAsync(Socket, IPAddress, Int32) ConnectAsync(Socket, IPAddress, Int32) ConnectAsync(Socket, IPAddress, Int32)

与远程主机建立连接。Establishes a connection to a remote host. 主机由 IP 地址和端口号指定。The host is specified by an IP address and a port number.

ConnectAsync(Socket, IPAddress[], Int32) ConnectAsync(Socket, IPAddress[], Int32) ConnectAsync(Socket, IPAddress[], Int32) ConnectAsync(Socket, IPAddress[], Int32)

与远程主机建立连接。Establishes a connection to a remote host. 主机由 IP 地址数组和端口号指定。The host is specified by an array of IP addresses and a port number.

ConnectAsync(Socket, String, Int32) ConnectAsync(Socket, String, Int32) ConnectAsync(Socket, String, Int32) ConnectAsync(Socket, String, Int32)

与远程主机建立连接。Establishes a connection to a remote host. 主机由主机名和端口号指定。The host is specified by a host name and a port number.

ReceiveAsync(Socket, ArraySegment<Byte>, SocketFlags) ReceiveAsync(Socket, ArraySegment<Byte>, SocketFlags) ReceiveAsync(Socket, ArraySegment<Byte>, SocketFlags) ReceiveAsync(Socket, ArraySegment<Byte>, SocketFlags)

接收连接的套接字发出的数据。Receives data from a connected socket.

ReceiveAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags) ReceiveAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags) ReceiveAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags) ReceiveAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags)

接收连接的套接字发出的数据。Receives data from a connected socket.

ReceiveAsync(Socket, Memory<Byte>, SocketFlags, CancellationToken) ReceiveAsync(Socket, Memory<Byte>, SocketFlags, CancellationToken) ReceiveAsync(Socket, Memory<Byte>, SocketFlags, CancellationToken) ReceiveAsync(Socket, Memory<Byte>, SocketFlags, CancellationToken)
ReceiveFromAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint) ReceiveFromAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint) ReceiveFromAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint) ReceiveFromAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint)

接收来自指定网络设备的数据。Receives data from a specified network device.

ReceiveMessageFromAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint) ReceiveMessageFromAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint) ReceiveMessageFromAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint) ReceiveMessageFromAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint)

使用指定的 SocketFlags 将指定字节数的数据接收到指定的数据缓冲区位置,并存储终结点和数据包信息。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.

SendAsync(Socket, ArraySegment<Byte>, SocketFlags) SendAsync(Socket, ArraySegment<Byte>, SocketFlags) SendAsync(Socket, ArraySegment<Byte>, SocketFlags) SendAsync(Socket, ArraySegment<Byte>, SocketFlags)

将数据发送到连接的套接字。Sends data to a connected socket.

SendAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags) SendAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags) SendAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags) SendAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags)

将数据发送到连接的套接字。Sends data to a connected socket.

SendAsync(Socket, ReadOnlyMemory<Byte>, SocketFlags, CancellationToken) SendAsync(Socket, ReadOnlyMemory<Byte>, SocketFlags, CancellationToken) SendAsync(Socket, ReadOnlyMemory<Byte>, SocketFlags, CancellationToken) SendAsync(Socket, ReadOnlyMemory<Byte>, SocketFlags, CancellationToken)
SendToAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint) SendToAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint) SendToAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint) SendToAsync(Socket, ArraySegment<Byte>, SocketFlags, EndPoint)

以异步方式将数据发送到特定远程主机。Sends data asynchronously to a specific remote host.

安全性

SocketPermission
建立传出连接或接受传入的请求。To establish an outgoing connection or accept an incoming request.

适用于

线程安全性

此类的实例是线程安全的。Instances of this class are thread safe.

另请参阅