SocketIO从节点服务器发送到Python客户端
我正在寻找一种从NodeJS服务器向客户机Python发出指令的方法 我的服务器从Web界面接收“指令”,并且连接正常。 但是,我无法将此指令发送到我的客户机(使用Python) 主旨: -NodeJSSocketIO从节点服务器发送到Python客户端,python,node.js,python-2.7,socket.io,Python,Node.js,Python 2.7,Socket.io,我正在寻找一种从NodeJS服务器向客户机Python发出指令的方法 我的服务器从Web界面接收“指令”,并且连接正常。 但是,我无法将此指令发送到我的客户机(使用Python) 主旨: -NodeJS socket.on('instruction', function (jsonMessage){ ... socket.emit('deleteFile', jsonMessage); }; -Python from socketIO_cli
socket.on('instruction', function (jsonMessage){
...
socket.emit('deleteFile', jsonMessage);
};
-Python
from socketIO_client_nexus import SocketIO
import json
...
def on_deleteF(*args):
#I just try to print something first
print('test delete')
...
mainSocket = SocketIO('0.0.0.0', 3000)
mainSocket.on('deleteFile', on_deleteF)
我不知道我在思考socket.emit('deleteFile')、Python中的“.on”或两者时是否犯了错误
所以,如果你能给我解释一下做事情的好方法,思考的好方法。感谢您为客户机创建了一个登录事件,以将其套接字id与自己的id存储在一起,然后您使用其套接字id通过其特定套接字向客户机发出指令:
var clients=new Array();
...
socket.on('login', function(){
clients[idClient] = socket.id
.....
socket.on('instruction', function (jsonMessage, idClient){
io.to(clients[idClient]).emit('deleteFile', jsonMessage);
谢谢你,这对我帮助很大!