In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to further use tcp, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Previous knowledge of socket is limited to the superficial use of API such as listen/connect/epoll/select/close. Its specific semantics and some states have not been studied in depth. I always thought there would be something wrong with writing code like this. Today, I gritted my teeth and read the Tcp part of "tcp Protocol Volume 1" again. It is found that many mistakes have been made in the program due to the lack of understanding of the protocol and the semantics of API.
TIME_WAIT state is the most difficult to understand in tcp network programming. The active shutdown party will experience the TIME_WAIT state, which will go through the 2MSL time. The purpose is to reliably terminate the TCP full-duplex connection and allow the old duplicate packets to disappear in the network (see UNP P37 for details).
The duration of TIME_WAIT is typically 1 minute to 4 minutes. If a large number of connections pour in during this period, and then the server disconnects them, it will result in a large number of connections remaining on the server to handle TIME_WAIT, which in theory will seriously slow down the performance of the system.
Therefore, as long as conditions permit, you should try to allow the client to actively disconnect.
Because the server is bound to a fixed port, when the server is restarted, as long as there is a connection with the TIME_WAIT status accessed through this fixed port, it will cause the bind to fail. Therefore, the server must set the SO_REUSEADDR property for the socket of bind.
The default behavior of close first subtracts the descriptor reference count by one, and executes the close process if the reference count is 0. That is, mark the socket as closed and immediately return to the calling process, where the socket can no longer be used by the calling process. However, tcp will attempt to send any data that has been queued to be sent to the peer, and the normal tcp connection termination sequence (that is, four waves) will be executed after the transmission is closed. This behavior can be changed through SO_LINGER.
Shutdown's behavior is a little more crude than that of close.
No matter how many processes hold the socket, once the socket is shutdown, all processes can no longer perform the shutdown operations on the socket. Shutdown can turn off reading and writing, respectively.
When shutdown writes, it sends all the data in the current send buffer before the connection termination sequence is carried out.
When shutdown reads, it empties all the data in the current receive buffer.
In the implementation of silly, my implementation of close simply crudely emptied all send buffers and then turned off socket.
Comparing the close and shutdown functions of the system, we can find that this is wrong, because when the application layer calls close, the data may not be sent out, which may cause the information received by the client not to be completed, resulting in other bug.
On how to further use tcp to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.