websocket连接不上,
后台flask+uwsgi+flask-socketio
web端可以正常连接。
小程序各种姿势连不上,报错信息:
VM1800 asdebug.js:1 WebSocket connection to 'ws://x.x.x.x:5000/socket.io/?EIO=3&transport=wobsocket' failed: Error during WebSocket handshake: Unexpected response code: 400
tcp抓包发现,web连接的时候,在 cookie 字段里面有两个值:io=xxxx&session=xxxx
小程序连接的时候, cookie字段只有一个值,session=xxx,倒是 UA 里面有个 token 不知道干嘛用的。
除此之外请求头一模一样。
请教,这个问题应该如何解决?
请问你的问题解决了吗?
麻烦提供能复现问题的代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
// 是ws请求,现在还开发没有配ssl
wx.connectSocket({
url: 'ws://myurl',
header:{
'content-type': 'application/json'
},
protocols: ['protocol1']
})
后台代码(Flask+uwsgi+flask-socketio):
@socketio.on('connect')
def connect():
return view.connect()
def connect():
sid = request.sid
session['sid'] = sid
uid = session.get('id')
user = User.query.filter(User.id == uid).first()
if not user:
return {'msg': 'fail', 'data': 'Not the user'}
usersEquipments = user.group.equipments
if not usersEquipments:
return {'msg': 'success', 'data': 'Havent equipment in this user'}
for e in usersEquipments:
join_room(e.id, sid=sid, namespace='/')
socketio.emit(
'join',
{'data': 'OK', 'joiner': session.get('username')},
room=e.id,
callback=callback
)
return {'msg': 'success', 'data': 'OK, The user {} has joined equipments room'.format(session.get('username'))}