测试步骤
1、网络调试助手,协议类型选择TCP Server,本地主机地址选择127.0.0.1,打开一个8995端口
2、打开客户端测试工具
3、客户端连接 ws://127.0.0.1:8996/
let wsPath ="ws://127.0.0.1:8996/"
export function initWebSocket(callback){
if (typeof(WebSocket) === "undefined") {
alert("您的浏览器不支持socket")
} else {
//断掉重连使用ReconnectingWebSocket
socket = new ReconnectingWebSocket(wsPath )
// 监听socket连接
socket.onopen = function(e){
console.log("sucess")
}
// 监听socket错误信息
socket.onerror = function(e){
console.log("error");
}
socket.onclose = function(e){
console.log("close");
}
//接收数据
socket.onmessage = function(e){
console.log(e.data);
}
}
4、网络调试助手发送测试数据即可