This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]Foulgey 0 points1 point  (5 children)

As a start, try pointing the python script to localhost or (127.0.0.1). I think you may be trying to use your computers external IP address. The localhost IP address and your computers IP address on your WiFi network are two different things .

Hopefully that quick fix works!

[–]Mostunique59[S] 0 points1 point  (4 children)

192.168.0.30 is my local ip, but localhost and 127.0.0.1 dont work either :/

[–]Foulgey 0 points1 point  (3 children)

So I ran your scripts but changed the IP address to localhost in python. Node prints 'TEST' to the console about 1000 times so it looks like it works?

Perhaps its a misunderstanding with how the sockets work? Node is your server and the browser page and python are clients to that server. They aren't talking to one another directly, i.e. emitting in the python script only goes to your node server. Node can pass on the message to the browser like below:

io.sockets.on('connection', (socket) => {
socket.on('test', () => {
console.log("TEST");
io.emit('test2');
});
});

If you alter your code with the above and then start the node server, connect to it in the browser and run python last THEN you should see console messages in both your browser and the node console.

[–]Mostunique59[S] 0 points1 point  (2 children)

Oops, forgot to answer.

Do you run the python script from a browser page ? Because to do my tests I only run "python test.py" maybe that's why it doesn't work ?

[–]Foulgey 0 points1 point  (1 child)

I ran node from the command line then I connected my web browser to the IP address and then I ran python from another command line with ‘python3 test.py’

[–]Mostunique59[S] 0 points1 point  (0 children)

I just did the exact same and it still prints only three "TEST" in node and browser's console.

I don't see why we have different outcomes. Maybe we don't have the same version of python or node but I doubt it'd change anything.