To send pictures and videos with WebSocket, how do clients differentiate between different data (text, pictures)? )?

Source: Internet
Author: User
JS Operation just like this

ws = new WebSocket($("#uri").val());    //连接成功建立后响应        ws.onopen = function() {        }    //收到服务器消息后响应        ws.onmessage = function(e) {        }        //连接关闭后响应        ws.onclose = function() {            ws = null;        }

What is the JS interface?

Reply content:

JS Operation just like this

ws = new WebSocket($("#uri").val());    //连接成功建立后响应        ws.onopen = function() {        }    //收到服务器消息后响应        ws.onmessage = function(e) {        }        //连接关闭后响应        ws.onclose = function() {            ws = null;        }

What is the JS interface?

WebSocket is just a long-connected communication protocol that does not provide actual business functionality.
The content of the transmission needs the communication both sides (front-end and back-end) to negotiate a message format, specify the type, content, such as the acquisition of the field, after a good agreement, all of this data encapsulation and analysis.

Generally speaking websocket suitable for the transfer of text data, although the Protocol also provides the ability to transmit binary data, but JS processing binary system is really not to force AH. So the binary data is encoded as text data, so there are many ways, such as Base64, and then send it in the past can be. 1 floor of the answer is very good, very clear. I think the landlord of the agreement or the like is not very clear, suggest to look at this aspect of the book, it is very useful to improve the level of programming.

  • Related Article

    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.