After the client is connected to the server, what will happen next? What should I do if the connection is closed? I do not need to reconnect. How can I know that the other party is alive? What is the impact of force disconnection on the other?
Next, answer the following questions one by one.
[Client]
- Reconnect task: if the session is closed, you can try to reconnect the task, for example, increasing the number of reconnection tasks. The specific connection process is no different from the general client connection establishment process.
- Heartbeat packet determination: if the session is idle, you can try to send some heartbeat packets to check whether the listener can normally receive the heartbeat packet response.
[Server side]
- What should I do if the connection is disconnected? If the server does not perform regular scanning, it will be disconnected when it is disconnected. Otherwise, it will not be unnecessary.
[If one party closes, what does the other party do? What should I do ?]
- When the client is closed, how does the server do it?
A ). if the server reads/writes data correctly, the following error occurs: "Java. io. ioexception: the remote host forces an existing connection to be closed, and the existing content on the socket will be "lost ".
B) The server can close the connection normally without re-connection tasks.
- What should I do if the server is closed?
A ). if the client is reading/writing correctly at this time, an error is returned: "Java. io. ioexception: the remote host forces an existing connection to be closed, and the existing content on the socket will be "lost ".
B) Start the reconnection task.
- What if the server is not started when the client tries to connect?
A) The client will receive the error "connection refused ."