A. TCP / UDP basics
- TCP / UDP contrast
- TIME_WAIT state
- And buffer size limit
- socket related structures and details
- socket each process-related interfaces should pay attention to local
- Combing fork concurrent services FAQ
Two. I / O multiplexing
- select
- epoll
1.1 TCP / UDP contrast
items | TCP | UDP |
---|---|---|
Connect and establish | Three-way handshake | Without connecting operation is transmitted directly |
Data transmission | Process buffer is copied to the send buffer if the send buffer blocking the plug does not fit until transmit buffer is empty to continue the replication process buffer does not exist, so write only show returns successfully transmit buffer is available, does not mean that the data has been sent to the peer, the transmit buffer contents reserved until you receive the correct reply | Process buffer is copied directly to the kernel buffer, too large an error is returned, otherwise sent directly, and discard the transmitted data |
Process | bind/listen/accept/connect | sendto/recvfrom |
Packet structure | Address / serial number / congestion control / check / data + offset, | Information / Checksum / data length + |
1.2 TIME_WAIT state
- TIME_WAIT state reason to exist:
1) reliably achieve full-duplex TCP connection is terminated
to ensure the final ACK packet sent by the client to reach the server, because this ACK packets may be lost, standing on the perspective of the server seems that I have sent a FIN + ACK packet Wen request disconnected, the client has not responded to me, should I send the request to disconnect it did not receive the message, so the server will resend once, and the client can receive in this period 2MSL this retransmission of packets, and then give a response packet, and 2MSL will restart the timer.2) to allow passage of the old packets in the network
to prevent similar "three-way handshake" mentioned in the "connection request has failed segment" appear in this connection. After the last client sends a confirmation message, 2MSL this time, it is possible to connect all the segments present within the duration of the generated disappeared from the network. Such new connection request packet old connection does not occur.