Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

TcpState Enumeration

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

Namespace:  System.Net.NetworkInformation
Assembly:  System (in System.dll)

public enum TcpState

Member nameDescription
UnknownThe TCP connection state is unknown.
ClosedThe TCP connection is closed.
ListenThe local endpoint of the TCP connection is listening for a connection request from any remote endpoint.
SynSentThe 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.
SynReceivedThe local endpoint of the TCP connection has sent and received a connection request and is waiting for an acknowledgment.
EstablishedThe TCP handshake is complete. The connection has been established and data can be sent.
FinWait1The 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.
FinWait2The local endpoint of the TCP connection is waiting for a connection termination request from the remote endpoint.
CloseWaitThe local endpoint of the TCP connection is waiting for a connection termination request from the local user.
ClosingThe local endpoint of the TCP connection is waiting for an acknowledgement of the connection termination request sent previously.
LastAckThe local endpoint of the TCP connection is waiting for the final acknowledgement of the connection termination request sent previously.
TimeWaitThe 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.
DeleteTcbThe transmission control buffer (TCB) for the TCP connection is being deleted.

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 http://www.ietf.org.

The following code example counts the established TCP connections.


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);
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2015 Microsoft