websocket客户端接收数据

宇文鸣
2023-12-01

连接服务器IP:192.168.20.55及其端口号3002, 并接收数据

function handleWSReceive() {
    this.ws = new WebSocket("ws://192.168.20.55:3002"); // websocket接收IP地址端口
    this.ws.onopen = function () {
        console.log('3002端口:连接成功');
    }
    this.ws.onmessage = function (event) {
        console.group('3002端口:接收数据');
        console.log(event.data);
        console.groupEnd();
    }
    this.ws.onclose = function () {
        console.log('3002端口:连接断开');
    }
}

handleWSReceive();

 

 类似资料: