web Socket 总结

序:客户端和服务端网络通讯的方式为HTTP、WS:HTTP 由客户端发起请求,服务端进行回应;WS 由客户端和服务端保持实时通信,可以接受服务端推送的消息。

    HTTP =  TCP + HTTP ; HTTPS = TCP + TLS + HTTP

    WS = TCP + WS ; WSS = TCP + TLS + WS


客户端用法:

let ws = new WebSocket(url);

ws.onopen = function(){}

ws.onmessage = function(){}

ws.onclose = function(){}

ws.onerror = function(){}

ws.binaryType = 'blob'  //  'arraybuffer'

ws.send()

ws.bufferedAmount === 0  // 表示还有多少字节的二进制数据没有发送

你可能感兴趣的:(web Socket 总结)