其他分享
首页 > 其他分享> > webSocket实现

webSocket实现

作者:互联网

webSocket实现方法

封装一个函数,开局调用就行

connectWS() {
	  var ws = null
      ws = new WebSocket(  
       // "ws://192.168.199.187:9005/websocket/" 地址找后端
      );
     ws.onopen = function (evt) {
        console.log("Connection open ...");
      };
     ws.onmessage = (e) => {
        console.log('webSocket收到消息: ' + e.data)  //数据处理可能有些复杂
    },
    ws.onclose = function (e) {
            console.log('webSocket关闭: ')
          }
    ws.onerror = function (e) {
            console.log('webSocket错误: ')
          }

标签:function,webSocket,log,实现,onerror,ws,console
来源: https://blog.csdn.net/weixin_44278376/article/details/115548504