socket的简单使用

发布于 5 年前作者 jie581255 次浏览最后编辑 5 年前来自 share
   let webSocketTask = null;

  webSocketCon() {

    let that = this;

    that.webSocketTask = wx.connectSocket({

      url'wss://socket.xxxxx.com',

      header: {

        'content-type''application/json'

      },

      successres => {

      },

      failfail => {

      },

    });

    // 打开连接
    that.webSocketTask.onOpen(res => {

    });

    // 接收
    that.webSocketTask.onMessage(res => {
  

    });

    // 关闭
    that.webSocketTask.onClose(err => {

    })

    // 错误
    that.webSocketTask.onError(err => {

     
    });

  },
0 回复
暂无回复