If you want to use websocket to send images and videos, how can the client differentiate different data (text, images ..)?

Source: Internet
Author: User
Js operations are like this: {code...} is there any js interface? js operations are like this.

Ws = new WebSocket ($ ("# uri "). val (); // response to ws after the connection is established successfully. onopen = function () {}// response to ws after receiving the Server Message. onmessage = function (e) {}// response to ws after the connection is closed. onclose = function () {ws = null ;}

Is there any js interface?

Reply content:

This is the case for js operations.

Ws = new WebSocket ($ ("# uri "). val (); // response to ws after the connection is established successfully. onopen = function () {}// response to ws after receiving the Server Message. onmessage = function (e) {}// response to ws after the connection is closed. onclose = function () {ws = null ;}

Is there any js interface?

Websocket is only a persistent connection communication protocol and does not provide actual service functions.
The transmitted content must be negotiated by both parties (both the frontend and backend) to determine how to obtain fields such as the type and content. after the information is agreed, data is encapsulated and parsed.

Generally, websocket is suitable for transmitting text data. although The protocol also stipulates that binary data can be transmitted, JS cannot handle binary data. Therefore, we need to encode binary data into text data. There are many such methods, such as base64, and then send it to the system. The answer on the first floor is also very good and clear. I think the landlord is not very clear about the protocol and so on. I suggest you read more books in this regard. it plays a very role in improving the programming level.

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.