TcpState Enumeration
Specifies the states of a Transmission Control Protocol (TCP) connection.
Assembly: System (in System.dll)
| Member name | Description | |
|---|---|---|
| Unknown | The TCP connection state is unknown. | |
| Closed | The TCP connection is closed. | |
| Listen | The local endpoint of the TCP connection is listening for a connection request from any remote endpoint. | |
| SynSent | 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 | The local endpoint of the TCP connection has sent and received a connection request and is waiting for an acknowledgment. | |
| Established | The TCP handshake is complete. The connection has been established and data can be sent. | |
| FinWait1 | 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 | The local endpoint of the TCP connection is waiting for a connection termination request from the remote endpoint. | |
| CloseWait | The local endpoint of the TCP connection is waiting for a connection termination request from the local user. | |
| Closing | The local endpoint of the TCP connection is waiting for an acknowledgement of the connection termination request sent previously. | |
| LastAck | The local endpoint of the TCP connection is waiting for the final acknowledgement of the connection termination request sent previously. | |
| TimeWait | 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 | The 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 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 'CountTcpConnections
void CountTcpConnections()
{
IPGlobalProperties* properties = IPGlobalProperties::GetIPGlobalProperties();
TcpConnection* connections[] = properties->GetActiveTcpConnections();
int establishedConnections = 0;
System::Collections::IEnumerator* myEnum1 = connections->GetEnumerator();
while (myEnum1->MoveNext())
{
TcpConnection* t = __try_cast<TcpConnection*>(myEnum1->Current);
if (t->State == TcpState::Established)
{
establishedConnections++;
}
Console::Write(S"Local endpoint: {0} ",t->LocalEndPoint->Address);
Console::WriteLine(S"Remote endpoint: {0} ",t->RemoteEndPoint->Address);
}
Console::WriteLine(S"There are {0} established TCP connections.", __box(establishedConnections));
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.