Reputation: 107
I'm looking for a way to emit an instruction from my NodeJS server to my client Python.
My server receive the 'instruction' from a Web Interface, and the connection works. But I am not able to emit this instruction to my client which is in Python.
Main idea :
- NodeJS
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)
I don't know if I made a mistake in my way of thinking socket.emit('deleteFile'), or on the '.on' in Python, or on both.
So if you can explain me the good way to do, the good way to think. Thanks
Upvotes: 2
Views: 454
Reputation: 1044
you create a login event for the client to store their socket id with their own id, then you emit the instruction to the client by their specific socket using their socket 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);
Upvotes: 1