收藏
回答

android真机无法建立socket连接,直接进入onSocketError?

模拟器和IOS真机均正常,android真机 打开调试,进入onSocketError,错误code1004



connectSocketFun: function() {
  console.log("开始连接设备")
  let wxs = this
  //建立连接
  wx.connectSocket({
    url: socketUrl + '/websocket/' + wxs.data.noWashCar.deviceNumber + '/' + wxs.data.noWashCar.numberPlate + '/' + wxs.data.noWashCar.orderId
  })
  let socketOpen = false
  const socketMsgQueue = []
  //连接成功
  wx.onSocketOpen(function(res) {
    wx.showLoading({
      title: '正在同步位置',
      mask: true
    })
    socketOpen = true
    console.log("res")
 
  })
 
  //接收数据
  wx.onSocketMessage(function(data) {
    console.log("data", data)
    // if (data.data == "SUCCESS") {
 
    console.log("接收的数据", data);
    if (data.data != "FAIL") {
      wxs.setData({
        deadShipCondition: JSON.parse(data.data).Data,
      })
      console.log("deadShipCondition", wxs.data.deadShipCondition)
      let mqtt_connect = ''
      let forward = ''
      let backward = ''
      let finished = ''
      let running = ''
      let text = ''
 
      let isSegment = ''
      for (let i in wxs.data.deadShipCondition) {
        //停车到位
        if (wxs.data.deadShipCondition[i].name == 'VEHICLE_POSITIONED') {
          mqtt_connect = wxs.data.deadShipCondition[i]
        }
 
        //指示灯提示向后(车辆位置靠前)
        if (wxs.data.deadShipCondition[i].name == 'BACKWARD') {
          forward = wxs.data.deadShipCondition[i]
        }
 
        //指示灯提示向前(车辆位置靠后)
        if (wxs.data.deadShipCondition[i].name == 'FORWARD') {
          backward = wxs.data.deadShipCondition[i]
        }
        //洗车中
        if (wxs.data.deadShipCondition[i].name == 'RUNNING') {
          running = wxs.data.deadShipCondition[i]
        }
 
        //清洗结束
        if (wxs.data.deadShipCondition[i].name == 'FINISHED') {
          finished = wxs.data.deadShipCondition[i]
        }
 
      }
 
      if (backward.value == 1) {
        text = "车辆向前"
      }
      if (forward.value == 1) {
        text = "车辆向后"
      }
      if (mqtt_connect.value == 1) {
        text = "停车到位"
      }
      if (running.value == 1) {
        text = "洗车中"
      }
      if (finished.value == 1) {
        text = "清洗结束"
      }
 
      let nvabarDataTitle = 'nvabarData.title'
 
      wxs.setData({
        [nvabarDataTitle]: text,
        //停车到位
        mqtt_connect: mqtt_connect,
        //交通灯指示向前
        FORWARD: forward,
        //交通指示灯向后
        BACKWARD: backward,
        //洗车完成
        FINISHED: finished,
        //洗车进行中
        RUNNING: running,
        // isSegment: isSegment
        // noCarInPlace:1
      })
      if (wxs.data.FINISHED.value == 1) {
        wx.closeSocket()
      }
      wx.hideLoading()
    } else {
 
      wx.hideLoading()
      wx.showToast({
        title: '暂无车辆到位',
        icon: 'none'
      })
      wxs.setData({
        noCarInPlace: 0
      })
    }
 
  })
  wx.onSocketError((errMsg) => {
    console.log("socket连接失败", errMsg)
  })
 
},


最后一次编辑于  11-25
回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员-小柿子
    社区技术运营专员-小柿子
    11-25

    麻烦在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,麻烦提供一下微信号,复现的具体时间点

    11-25
    赞同
    回复 3
    • 大耳朵图图
      大耳朵图图
      11-25
      已上传,具体时间点在2019年11月25日上午10点38分左右,请问微信号还要给您提供吗?
      11-25
      回复
    • 大耳朵图图
      大耳朵图图
      11-25
      微信号已私信
      11-25
      回复
    • 大耳朵图图
      大耳朵图图
      11-25
      微信号:"and-you--"
      11-25
      回复
  • 大耳朵图图
    大耳朵图图
    11-25

    问题已解决! 确认问题出在socket地址传参上面,一旦带有中文字符需要encodeURI


    11-25
    赞同 1
    回复
问题标签