2

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

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You, it helped me a lot !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.