Understanding TCP socket states (Doc ID 1003531.1)

rongshiyuan發表於2014-11-20

Understanding TCP socket states (Doc ID 1003531.1)


Applies to:

Solaris SPARC Operating System - Version 8.0 to 11 11/11 [Release 8.0 to 11.0]
All Platforms
***Checked for relevance on 23-Oct-2014***

Goal

This document provides information about all TCP socket states

Solution

The possible state values for TCP sockets are as follows:

(Refer to "man netstat".)

BOUND         Bound, ready to connect or listen.

CLOSED        Closed. The socket is not being used.

CLOSING       Closed, then remote shutdown; awaiting acknowledgment.

CLOSE_WAIT    Remote shutdown; waiting for the socket to close.

ESTABLISHED   Connection has been established.

FIN_WAIT_1    Socket closed; shutting down connection.

FIN_WAIT_2    Socket closed; waiting for shutdown from remote.

IDLE          Idle, opened but not bound.

LAST_ACK      Remote shutdown, then closed; awaiting acknowledgment.

LISTEN        Listening for incoming connections.

SYN_RECEIVED  Active/initiate synchronization received and the connection under way

SYN_SENT      Actively trying to establish connection.

TIME_WAIT     Wait after close for remote shutdown retransmission.

 



The following explains relationship between system calls of socket program and TCP socket states.

    TCP socket program                                TCP socket states
==========================                        ==========================
Server          Client                            Server          Client

socket()        socket()                          IDLE            IDLE

bind()                                            BOUND           IDLE

listen()                                          LISTEN          IDLE

accept()
read()  
write()  -----&gt read()

close() 

 


Connection Phase in detail

               Server          Client

                 |      Syn       |
    SYN_RECEIVED |
						

 
      
Closing Phase in detail

               Server          Client

                 |      Fin       |
      CLOSE_WAIT |
						

 

The following are the snoop output for a simple TCP connection.

# snoop -i -r port 1122
client -> server     TCP D=1122 S=33165 Syn Seq=2277924106 Len=0 Win=24820
server -> client     TCP D=33165 S=1122 Syn Ack=2277924107 Seq=484525574 Len=0 Win=8760
client -> server     TCP D=1122 S=33165     Ack=484525575 Seq=2277924107 Len=0 Win=24820
client -> server     TCP D=1122 S=33165     Ack=484525575 Seq=2277924107 Len=256 Win=24820
server -> client     TCP D=33165 S=1122     Ack=2277924363 Seq=484525575 Len=0 Win=8504
server -> client     TCP D=33165 S=1122     Ack=2277924363 Seq=484525575 Len=256 Win=8760
client -> server     TCP D=1122 S=33165     Ack=484525831 Seq=2277924363 Len=0 Win=24820
client -> server     TCP D=1122 S=33165 Fin Ack=484525831 Seq=2277924363 Len=0 Win=24820
server -> client     TCP D=33165 S=1122     Ack=2277924364 Seq=484525831 Len=0 Win=8760
server -> client     TCP D=33165 S=1122 Fin Ack=2277924364 Seq=484525831 Len=0 Win=8760
client -> server     TCP D=1122 S=33165     Ack=484525832 Seq=2277924364 Len=0 Win=24820
 

Document Details

 
     
 

Related Products

 
     
 

Information Centers

 
     
 

Document References

 
No References available for this document.
     
 

Recently Viewed

 
     

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17252115/viewspace-1340782/,如需轉載,請註明出處,否則將追究法律責任。

相關文章