TCP: terminating a connection 3
来源:互联网 发布:淘宝网男士真皮皮衣 编辑:程序博客网 时间:2024/06/17 22:01
TCP: terminating a connection
- Terminating a TCP connection
- Closing a TCP connection is amuch easiest than establishing a TCP connection(it is usually easier to destroy than to build....)
The process is very much like ordinary data transfer - with thelast ACK step "dangling"
- Properties of the disconnect operation:
- Symmetric
- Independent
- The TCP disconnect operation issymmetric
In other words:
- Both the client and server can initiate thedisconnect operation.
(The connection request is always initialized by the client)
- The TCP disconnect operation isindependent
In other words:
- It is possible for one side toclose its TCP connection without havingthe other end of the connectionto be closed...
- The remaining TCP connection is auni-directional connection
- Effect of closing a TCP connection:
- The TCP module that closes its TCP connection will no longer be able totransmit
- The TCP module that has closed its TCP connectioncan still continue to receive datafrom the other end !!!
(Recall that a TCP connection is uni-directional)
- Programming note:
- The socket application programming interface (API)do not support a one-sided close operation....
In a TCP socket, when one end of the TCP socket is closed, theother end of the TCP socket iscloses by the API automatically.
- The Transport Layer Interface (TLI)fromAT&T does support one sided closing of aTCP end point...
The function t_sndrel(int fd) willrelease the send capabilityof the TCP end.
- The socket application programming interface (API)do not support a one-sided close operation....
- Closing a TCP connection is amuch easiest than establishing a TCP connection(it is usually easier to destroy than to build....)
- Message exchanges in the disconnection operation of TCP
- TCP close is also known as disconnect
- The messages exchanged in theTCP disconnection protocol when theclient closes its connection --- is as follows:
- Client sends a FIN request:
The FIN message (the FIN bit in the TCP header is set) is used to disconnect aTCP connection
- Server acknowledges theclient's FIN request:
When the server TCP module received the FIN request, it does:
- Send an ACK reply to the sender
- Invalid the ACK number
- Client processes the ACK reply:
When the sender of the FIN request received theACK reply, it invalidates its sequence number
(Now the client cannot send message because its sequence number isinvalid)
Note:
- The reverse TCP connection isnot closed:
The server has a valid sequence number !!!
- We say that the TCP connection"half close".
- (In the text book (if you bought one), theTCP state after closing one direction corresponds totheFIN_WAIT_2 state
It is not the CLOSED state --- in the CLOSED state, both TCP connections areclosed).
- While in the FIN_WAIT_2 state, theTCP module can still receive messages fromits peer...
- Client sends a FIN request:
- Closing a "half open" TCP connection
- At a later time, the other TCP module will also invoke aclose operation
The TCP module will also senda FINISH request to its peer.
There is a small difference in thisclose procedure...
- Messages exchanged in closing the half open TCP connection (on behalf of the server):
- Server sends FIN (disconnect) request:
- The client acknowledges theFINISH request:
NOTE:
- The client sends an ACK for theFIN request
- Then the client invalidates theACK number
- Now the client's TCP state iscompletely empty !!!
Now, you may be thinking that the TCP close operation at theclient is completed
NO !!!, not yet...
Reason:
- The ACK message (for the FIN request can be lost:
- The server would then time out andretransmit the FIN request:
- This would lead to an abnormal termination of theTCP connection:
- The ACK message (for the FIN request can be lost:
- To minimize the likelihood of abnormal termination ofhalf open TCP connection, the client will:
- wait 2 x MSL (Maximum Segment Livetime) beforeremoving the TCP state record
- MSL is the maximum amount time that a packet can "live"in the Internet
(due to routing errors, packets can be routingto very strange places in the Internet, but through the TTLfield, the lifetime of packets is limited.)
We can't never be sure what MSL really is (depends on how congesteddifferent routers are...
- MSL is set conservatively to 120 sec (2 min).
So the client will wait 4 min (2 × MSL) before removing theTCP state record
- MSL is set conservatively to 120 sec (2 min).
Example:
- ACK is lost
- Server retransmits theFIN request
The client retransmits theACK...
- wait 2 x MSL (Maximum Segment Livetime) beforeremoving the TCP state record
- Finally, when the server receives theACK, it deletes the TCP state record:
Now the server does not have any record of thisTCP connection
- After 2 × MSL delay, theclient will also delete the TCP state record:
- Server sends FIN (disconnect) request:
- Note:
- There is still a slight chance that after240 sec (2 x MSL) of waiting, a retransmitted FIN request arrive.
But such an event is rare
- There is still a slight chance that after240 sec (2 x MSL) of waiting, a retransmitted FIN request arrive.
- At a later time, the other TCP module will also invoke aclose operation
- Simultaneous closing
- Because each termination is indepedent of each other,it is possible that both TCP modulesinitiate theclose operation simultaneously.
- The messages exchanged in such case are as follows:
Notes:
- Both TCP modules send a FIN request
- Both TCP modules reply with anACK
After sending the ACK,each TCP protocol modulemust wait2 x MSL (240 sec) before removing the TCP state record
- TCP: terminating a connection 3
- TCP closing a connection
- A sample for TCP connection
- How TCP Establishes A Connection
- Terminating a Process
- Establishment of a TCP connection, state diagram
- 3-way TCP connection establishment
- 严重 [RMI TCP Connection(3)-127.0.0.1]
- TCP Connection Established! ^_^
- Kill TCP Connection源代码
- TCP Connection Termination
- TCP Connection Termination
- 6.5 TCP Connection Repair
- How To Set Up a TCP/IP Peer-to-Peer Network Connection
- A connection attempt failed because the connected party did not (trying to connect via tcp://localho
- 5种TCP连接中出现RST的情况。连接复位Reset a connection.
- A Simple SMB Connection
- Connection Establishment in TCP 2
- Connection Establishment in TCP 2
- HTTP协议很经典的解释
- TCP: Reliable Data transfer 3
- linux下memcached的启动/结束的方式
- LeetCode-Plus One
- TCP: terminating a connection 3
- Flow Control in TCP 3
- POJ-2404 Jogging Trails (中国邮递员)
- Linux下安装MySQL后设置root密码
- Struts1标签库
- Port Address Translation: saving IP addresses
- java中的线性表的内部实现(ArrayList、LinkedList)
- 如何对待一个人好
- 2014.9.13模拟赛【环上的游戏】