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.