socket的简单使用
发布于 3 年前 作者 jie58 939 次浏览 来自 分享
   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 => {

     
    });

  },
回到顶部