TcpState TcpState TcpState TcpState Enum

定义

指定传输控制协议 (TCP) 连接的状态。Specifies the states of a Transmission Control Protocol (TCP) connection.

public enum class TcpState
public enum TcpState
type TcpState = 
Public Enum TcpState
继承

字段

Closed Closed Closed Closed 1

TCP 连接处于关闭状态。The TCP connection is closed.

CloseWait CloseWait CloseWait CloseWait 8

TCP 连接的本地终结点正在等待来自本地用户的连接终止请求。The local endpoint of the TCP connection is waiting for a connection termination request from the local user.

Closing Closing Closing Closing 9

TCP 连接的本地终结点正在等待对先前发送的连接终止请求的确认。The local endpoint of the TCP connection is waiting for an acknowledgement of the connection termination request sent previously.

DeleteTcb DeleteTcb DeleteTcb DeleteTcb 12

正在删除 TCP 连接的传输控制缓冲区 (TCB)。The transmission control buffer (TCB) for the TCP connection is being deleted.

Established Established Established Established 5

TCP 握手完成。The TCP handshake is complete. 已建立连接,可以发送数据。The connection has been established and data can be sent.

FinWait1 FinWait1 FinWait1 FinWait1 6

TCP 连接的本地终结点正在等待来自远程终结点的连接终止请求或对先前发送的连接终止请求的确认。The local endpoint of the TCP connection is waiting for a connection termination request from the remote endpoint or for an acknowledgement of the connection termination request sent previously.

FinWait2 FinWait2 FinWait2 FinWait2 7

TCP 连接的本地终结点正在等待来自远程终结点的连接终止请求。The local endpoint of the TCP connection is waiting for a connection termination request from the remote endpoint.

LastAck LastAck LastAck LastAck 10

TCP 连接的本地终结点正在等待对先前发送的连接终止请求的最终确认。The local endpoint of the TCP connection is waiting for the final acknowledgement of the connection termination request sent previously.

Listen Listen Listen Listen 2

TCP 连接的本地终结点正在侦听来自任何远程终结点的连接请求。The local endpoint of the TCP connection is listening for a connection request from any remote endpoint.

SynReceived SynReceived SynReceived SynReceived 4

TCP 连接的本地终结点已发送并收到连接请求并且正在等待确认。The local endpoint of the TCP connection has sent and received a connection request and is waiting for an acknowledgment.

SynSent SynSent SynSent SynSent 3

TCP 连接的本地终结点已向远程终结点发送一个设置了同步 (SYN) 控制位的段标头并且正在等待匹配的连接请求。The local endpoint of the TCP connection has sent the remote endpoint a segment header with the synchronize (SYN) control bit set and is waiting for a matching connection request.

TimeWait TimeWait TimeWait TimeWait 11

TCP 连接的本地终结点正在等待足够的时间以便完成传递,以确保远程终结点收到了它的连接终止请求确认。The local endpoint of the TCP connection is waiting for enough time to pass to ensure that the remote endpoint received the acknowledgement of its connection termination request.

Unknown Unknown Unknown Unknown 0

TCP 连接状态是未知的。The TCP connection state is unknown.

示例

下面的代码示例计算建立的 TCP 连接数。The following code example counts the established TCP connections.

void CountTcpConnections()
{
   IPGlobalProperties ^ properties = IPGlobalProperties::GetIPGlobalProperties();
   array<TcpConnectionInformation^>^connections = properties->GetActiveTcpConnections();
   int establishedConnections = 0;
   System::Collections::IEnumerator^ myEnum1 = connections->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      TcpConnectionInformation ^ t = safe_cast<TcpConnectionInformation ^>(myEnum1->Current);
      if ( t->State == TcpState::Established )
      {
         establishedConnections++;
      }

      Console::Write( "Local endpoint: {0} ", t->LocalEndPoint->Address );
      Console::WriteLine( "Remote endpoint: {0} ", t->RemoteEndPoint->Address );
   }

   Console::WriteLine( "There are {0} established TCP connections.", establishedConnections );
}
public static void CountTcpConnections()
{
    IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
    TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
    int establishedConnections = 0;
    
    foreach (TcpConnectionInformation t in connections)
    {
        if (t.State == TcpState.Established)
        {
             establishedConnections++;
        }
        Console.Write("Local endpoint: {0} ",t.LocalEndPoint.Address);
        Console.WriteLine("Remote endpoint: {0} ",t.RemoteEndPoint.Address);
       
    }
     Console.WriteLine("There are {0} established TCP connections.",
        establishedConnections);
}
Public Shared Sub CountTcpConnections() 
    Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
    Dim connections As TcpConnectionInformation() = properties.GetActiveTcpConnections()
    Dim establishedConnections As Integer = 0
    
    Dim t As TcpConnectionInformation
    For Each t In  connections
        If t.State = TcpState.Established Then
            establishedConnections += 1
        End If
        Console.Write("Local endpoint: {0} ", t.LocalEndPoint.Address)
        Console.WriteLine("Remote endpoint: {0} ", t.RemoteEndPoint.Address)
    Next t 
    Console.WriteLine("There are {0} established TCP connections.", establishedConnections)

End Sub

注解

此枚举定义State属性的有效值。This enumeration defines valid values for the State property. TCP 是一个传输层协议, 负责可靠地发送和接收数据包。TCP is a transport layer protocol responsible for reliably sending and receiving data packets. 此枚举中的 TCP 状态在中提供https://www.ietf.org的 IETF RFC 793 中定义。The TCP states in this enumeration are defined in IETF RFC 793 available at https://www.ietf.org.

适用于