TcpState 列舉

定義

指定傳輸控制通訊協定 (TCP) 連線的狀態。

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

欄位

Closed 1

TCP 連線已關閉。

CloseWait 8

TCP 連線的本機端點正在等候來自本機使用者的連線終止 (Termination) 要求。

Closing 9

TCP 連線的本機端點正在等候先前傳送之連線終止要求的認可。

DeleteTcb 12

正在刪除 TCP 連線的傳輸控制緩衝區 (Transmission Control Buffer,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 狀態定義于 的 IETF RFC 793 中 https://www.ietf.org

適用於