Szerkesztés

Megosztás a következőn keresztül:


TcpState Enum

Definition

Specifies the states of a Transmission Control Protocol (TCP) connection.

public enum class TcpState
public enum TcpState
type TcpState = 
Public Enum TcpState
Inheritance
TcpState

Fields

Name Value Description
Unknown 0

The TCP connection state is unknown.

Closed 1

The TCP connection is closed.

Listen 2

The local endpoint of the TCP connection is listening for a connection request from any remote endpoint.

SynSent 3

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.

SynReceived 4

The local endpoint of the TCP connection has sent and received a connection request and is waiting for an acknowledgment.

Established 5

The TCP handshake is complete. The connection has been established and data can be sent.

FinWait1 6

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 7

The local endpoint of the TCP connection is waiting for a connection termination request from the remote endpoint.

CloseWait 8

The local endpoint of the TCP connection is waiting for a connection termination request from the local user.

Closing 9

The local endpoint of the TCP connection is waiting for an acknowledgement of the connection termination request sent previously.

LastAck 10

The local endpoint of the TCP connection is waiting for the final acknowledgement of the connection termination request sent previously.

TimeWait 11

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.

DeleteTcb 12

The transmission control buffer (TCB) for the TCP connection is being deleted.

Examples

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

Remarks

This enumeration defines valid values for the State property. TCP is a transport layer protocol responsible for reliably sending and receiving data packets. The TCP states in this enumeration are defined in IETF RFC 793 available at https://www.ietf.org.

Applies to