TCP connection, underlying Retry Mechanism, and heartbeat packet Mechanism

Source: Internet
Author: User

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 ."

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.