Simple instance---data format for. NET-based WebSocket

Source: Internet
Author: User

We have established a two-way communication between the server and the client, if you immediately drop the data according to previous experience, congratulations, the data can pass, but you do not know, it is natural, his site he wants to make the decision, WebSocket has its own agreed data format, We have to do it in this format.

Protocol this thing, very boring, can only use, can not innovate, but more understanding of some of these rules, for the future we define the transport protocol has a strong reference value, so we still have to look carefully.

Open: Http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10 Find the location as shown, which has detailed instructions

The specific description of each field, you can slowly chew English, we will discuss how to use this thing in our system.

First use my language to understand this format, what is wrong to welcome you to correct. In this format, the most important is the second byte:

1. The first decision whether there is a mask, if the mask is 1, there will be the back of the 4-byte Masking-key, the customer sent over the data, there is a value, so when I try to send an empty string come over, the server will receive a similar to the following data: (in 2 binary display, easy to understand).

Transmitted data, using the mask of the XOR operation to generate, for example, I send a character 1, the server will receive the following data:0001 0001 0011 1100 1001 0111 0011 1001 1010 1111 0000 1101If mask is 0, there is no subsequent mask

2. The latter 7 bits are used to determine the length of the frame, focusing on this sentence in the original text: Payload length:7 bits, 7+16 bits, or 7+64 bits if the 7 bits represent a length less than 126, then this is the actual length of the sent data if it equals 126, Then two bytes is the length, that is, if the meaning of the 7+16bits is equal to 127, then the 8 bytes is the length, that is, the meaning of the 7+64bits data Transfer Protocol, it should be reasonable to use every bit, although feel more tired, but can reduce the number of data transmission, This is when we design the agreement, we should study hard.

Simple instance---data format for. NET-based WebSocket

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.