JS operation is like this
<code>ws = new WebSocket($("#uri").val()); //连接成功建立后响应 ws.onopen = function() { } //收到服务器消息后响应 ws.onmessage = function(e) { } //连接关闭后响应 ws.onclose = function() { ws = null; }</code>
Is there any js interface
JS operation is like this
<code>ws = new WebSocket($("#uri").val()); //连接成功建立后响应 ws.onopen = function() { } //收到服务器消息后响应 ws.onmessage = function(e) { } //连接关闭后响应 ws.onclose = function() { ws = null; }</code>
Is there any js interface
Websocket is just a long connection communication protocol and does not provide actual business functions.
The transmitted content requires the communicating parties (front-end and back-end) to negotiate a message format that specifies how to obtain the type, content and other fields. Once agreed, data encapsulation and parsing are carried out accordingly.
Generally speaking, websocket is suitable for transmitting text data. Although the protocol also stipulates that binary data can be transmitted, JS is really not good at handling binary data. Therefore, it is better to encode the binary data into text data. There are many methods, such as base64, etc., and then send it over. The answer on the 1st floor is also very good and explained very clearly. I think the original poster is not very clear about protocols and the like. I suggest you read more books in this area. It is very useful for improving your programming level.