It's very different to see the code and write the code.

Source: Internet
Author: User

It's not hard to see the code, but it's not easy to write simple code from beginning to end.

Write a TCP server & client. It was changed from UDP, and it was a very old one.

The first listen error, the original Sock_dgram forget to change to Sock_stream,

Then found listen port is wrong, originally forgot Bind,

Later found that the client sends the data service side can not receive, and then look at the code, the original is no accept/connect.

Add accept and connect, the client prompt successfully, but the service side did not return, looked for a half-day, found that the client forgot to change the sock_dgram to Sock_stream.

It's too weak.

But finally changed, write this simple program, the purpose is to verify the following message sub-frame features:

Message Framing uses the message-framing mechanism to protect messages from the socket only within one boundary, which means that if the client sends 100 bytes to the server and then sends 50 bytes. Then the server reads 100 bytes and 50 bytes in two read operations respectively. This is also true for UDP, which is useful for message-oriented protocols. Unlike this, TCP is operated in a byte-stream manner. Without a framing mechanism, the data received at one end may be more or less than the data sent at the other end (this divides a write operation into multiple operations, or merges multiple writes into a single read operation). This behavior requires a message-oriented protocol that operates on top of TCP to provide data buffering and message framing mechanisms in the application layer (which can be a complex task).

It's very different to see the code and write the code.

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.