文档介绍:Socket 网络编程大纲? TCP/UDP ? Socket ? HTTP ? Unix IO 模型 TCP-UDP 对比 UDP ? User Datagram Protocol TCP ? Transmission Control Protocol TCP ——连接建立? Before a client attempts to connect with a server, the server must first bind to and listen at a port to open it up for connections: this is called a passive open. Once the passive open is established, a client may initiate an active open .– SYN : The active open is performed by the client sending a SYN to the server. The client sets the segment's sequence number to a random value A. – SYN-ACK : In response, the server replies with a SYN-ACK. The acknowledgment number is set to one more than the received sequence number (A + 1), and the sequence number that the server chooses for the packet is another random number, B. – ACK : Finally, the client sends an ACK back to the server. The sequence number is set to the received acknowledgement value . A + 1, and the acknowledgement number is set to one more than the received sequence number . B + 1. TCP ——连接关闭? The connection termination phase uses a four-way handshake, with each side of the connection terminating independently . ? When an endpoint wishes to stop its half of the connection, it transmits a FIN packet, which the other end acknowledges with an ACK . ? Therefore, a typical tear-down requires a pair of FIN and ACK segments from each TCP endpoint .? After both FIN/ACK exchanges are concluded, the side which sent the first FIN before receiving one waits for a timeout before finally closing the connection, during which time the local port is unavailable for new connections ; this prevents confusion due to delayed packets being delivered during subsequent connections. TCP ——连接关闭 TCP ——整个过程 TCP —— netstat ? LISTEN ?(server) represents waiting for a connection request from any remote TCP and port. ? SYN-SENT ?(client) represents waiting for a matching connection request after having sent a connection request. ? SYN-RECEIVED ?(server) represents waitin