Reputation: 11
I have looked at a lot of similar problems on message boards and read the related documentation and from what I can tell it seems like I am doing everything right.
node server code
io.on('connection', function(socket){
logger.log('info', `\n${Date().toLocaleString('short')}\n:: socket.io client connection established ::\nsocket.id: ${socket.id}\nsocket.handshake.address: ${socket.handshake.address}`)
socket.on('pythonTest', function(){
logger.log('info', `HI THIS IS PYTHON TALKING`)
});
socket.on('userConnect', function(userAgent){
logger.log('info', `\nhttp user connected\n${userAgent}`)
});
});
python client code
import socketio
from pprint import pprint
socket = socketio.Client()
socket.connect('http://localhost:3000')
pprint(vars(socket))
socket.emit('pythonTest', 'pythonTest')
When I launch the python script I can see that the socket connection works, however something is wrong with the event 'pythonTest'. The event 'userConnect' behaves as it should, but the emitter for 'userConnect' comes from a web browser which leads me to believe the problem is on the python side of things and not the event handler in node. Im thinking there is specifically something wrong with socket.emit('pythonTest', 'pythonTest') but I have no idea what it could be.
Upvotes: 0
Views: 650
Reputation: 11
Going to answer my own question here. Sorry if anyone was trying to figure this out as the info needed to solve wasn't there.
There was code I didnt show in my question because I mistakenly assumed other code couldnt be causing the problem.
The problem was caused by the eventlet library, specifically eventlet.monkey_patch() so if you're experiencing a similar problem and have that in your script try commenting it out.
Unfortunatly for me I can't remember why I had that line in my script in the first place. Note to self: use comments more.
I'm going to add eventlet to the question tags. If anybody has any insight into why this happens that would be nice.
Upvotes: 1