![](/img/trans.png)
[英]python-socketio client fails to get public data but NodeJS socket.io-client does not
[英]Python socket io client does'n accept connection but node client does
有一个节点服务器,我想与我的客户端执行套接字连接。 我可以连接节点,但 python 版本无法连接。
python 版本有什么问题?
const io = require('socket.io-client');
const socket = io("wss://winseller.turkmenexpress.ir", {
auth: {
token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwSWQiOiIyNyIsIm1vYmlsZSI6IjA5MTI3Mzk2Nzk0In0.moQMWb_I1CyhCJ9Gh4TLH8LiVwtE7h2wH4DPY-KEeT0"
}
});
socket.on('disconnect', function(data){
console.log('server is down');
})
socket.on('connect', function(data){
console.log('socket is connected');
})
import socketio
sio = socketio.Client()
sio.connect('wss://winseller.turkmenexpress.ir',auth={
'token': "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwSWQiOiIyNyIsIm1vYmlsZSI6IjA5MTI3Mzk2Nzk0In0.moQMWb_I1CyhCJ9Gh4TLH8LiVwtE7h2wH4DPY-KEeT0"
},wait=True, wait_timeout= 10
)
@sio.on('connect')
def connect():
print('socket is connected')
@sio.on('disconnect')
def disconnect():
print('server is down')
首先重新安装你的包,然后尝试以这种方式使用socketio
:
sio = socketio.Client()
@sio.event
def connect():
print('socket connected')
@sio.event
def my_message(data):
print('message received with ', data)
sio.emit('my response', {'response': 'my response'})
@sio.event
def disconnect():
print('socket disconnected from server')
sio.connect('wss://winseller.turkmenexpress.ir', auth={
'token': "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwSWQiOiIyNyIsIm1vYmlsZSI6IjA5MTI3Mzk2Nzk0In0.moQMWb_I1CyhCJ9Gh4TLH8LiVwtE7h2wH4DPY-KEeT0"
})
sio.wait()
我稍微更改代码只是为了检查它是否工作并且看起来很好。
import socketio
print('start...')
sio = socketio.Client()
sio.connect('wss://winseller.turkmenexpress.ir',auth={
'token': "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwSWQiOiIyNyIsIm1vYmlsZSI6IjA5MTI3Mzk2Nzk0In0.moQMWb_I1CyhCJ9Gh4TLH8LiVwtE7h2wH4DPY-KEeT0"
},wait=True, wait_timeout= 10
)
print('phase 1 ...', sio)
@sio.on('connect')
def connect():
print('socket is connected')
@sio.on('disconnect')
def disconnect():
print('server is down')
connect()
这是结果:
start...
phase 1 ... <socketio.client.Client object at 0x000001EC7FB96020>
socket is connected
所以除了结果你还期待什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.