TcpState 枚举

定义

指定传输控制协议 (TCP) 连接的状态。

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

字段

Closed 1

TCP 连接处于关闭状态。

CloseWait 8

TCP 连接的本地终结点正在等待来自本地用户的连接终止请求。

Closing 9

TCP 连接的本地终结点正在等待对先前发送的连接终止请求的确认。

DeleteTcb 12

正在删除 TCP 连接的传输控制缓冲区 (TCB)。

Established 5

TCP 握手完成。 已建立连接,可以发送数据。

FinWait1 6

TCP 连接的本地终结点正在等待来自远程终结点的连接终止请求或对先前发送的连接终止请求的确认。

FinWait2 7

TCP 连接的本地终结点正在等待来自远程终结点的连接终止请求。

LastAck 10

TCP 连接的本地终结点正在等待对先前发送的连接终止请求的最终确认。

Listen 2

TCP 连接的本地终结点正在侦听来自任何远程终结点的连接请求。

SynReceived 4

TCP 连接的本地终结点已发送并收到连接请求并且正在等待确认。

SynSent 3

TCP 连接的本地终结点已向远程终结点发送一个设置了同步 (SYN) 控制位的段标头并且正在等待匹配的连接请求。

TimeWait 11

TCP 连接的本地终结点正在等待足够的时间以便完成传递,以确保远程终结点收到了它的连接终止请求确认。

Unknown 0

TCP 连接状态是未知的。

示例

下面的代码示例对已建立的 TCP 连接进行计数。

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 。 TCP 是负责可靠地发送和接收数据包的传输层协议。 此枚举中的 TCP 状态在 上的 https://www.ietf.orgIETF RFC 793 中定义。

适用于