The code you attached just set up a server. You can add setSoTimeout when writing client communication, and you will understand what it is used for. Let's talk about the communication between QQ. I said something to you. May I have been waiting for your reply? It's simple.
2. Thread. Sleep
Socket adopts TCP protocol, so you can learn about TCP protocol first. First, you must determine what features you want to test. If it is the message sender, there is no need for thread hibernation. If the message is mixed with files, thread hibernation plays a role in avoiding file damage caused by wrong packet transmission order.