收藏
回答

安卓真机调试建立socket连接失败,直接进入onSocketError?


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

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 iin 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)
 
  })
 
  
 
},

日志已上传,微信号"and-you--",时间2019年11月25日14时43分

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

1 个回答

  • 大耳朵图图
    大耳朵图图
    11-25

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

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