Processing of TCP Application communication protocol

Source: Internet
Author: User

Processing of TCP Application communication protocol

Flyfish 2015-6-29

first-class processing
TCP is a stream protocol (stream protocol). The TCP data is passed to the receiver in the form of a byte stream, without the inherent "message" or "message boundary" or the user-visible "grouping" concept.
It simply transmits a byte stream, and we cannot accurately predict how many bytes will be returned in a particular read operation. Although the network layer data is transmitted in the form of IP packets between nodes, the amount of data in the packet is not directly related to how much data is sent to TCP in the send call. Also, there is no reliable way for the receiver to determine how the data is grouped, as multiple groupings may arrive between two recv calls. If your application is designed to be associated with how TCP is grouping data, redesign your application.
Processing "sticky packets", "subcontracting" because of the wrong understanding of the TCP data transmission model, when the word stream processing when the problem does not exist.

two detecting whether the client is online
Because TCP cannot immediately notify the application of the loss of the connection
TCP has an active (keep-alive) mechanism that can be used to detect dead connections, but this is usually of little use to the application. One of the main reasons why maintaining an active mechanism does not really become a connection monitoring mechanism is that the default time interval is too long.

can be used to detect more flexible
1 Heartbeat Detection: The client sends the message directly to the server "I am Online"
2 Heartbeat Detection: After the client connects to the server, a port number is sent to the server and then the heartbeat connection from the server is monitored on this port
3 Set a timer on the read operation, so that if the client does not make a request within a certain time interval, the server assumes that the client is no longer present.

Three uses defensive programming to prevent client unfriendly operation

1 Verify the client's valid data to prevent unintended behavior.
2 Checking for buffer overflow conditions

Refer to TCP/IP efficient programming: 44 Tips for improving network programs

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Processing of TCP Application communication protocol

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.