socket.emit inside socket.on function
Problem
Note: for support questions, please use one of these channels: stackoverflow or slack You want to: [ ] report a bug [x] request a feature Current behaviour invoke a socket.emit inside a socket.on function does not work. (see code below) ` socket.on('notification', function (data) { socket.emit('news', { hello: 'world' }); });` Steps to reproduce (if the current behaviour is a bug) Server side, emit a message from inside a "socket.on" method. Expected behaviour Message sent to client Setup - OS: Archlinux - browser: Firefox - socket.io version: 1.7.2 Other information (e.g. stacktraces, related issues, suggestions how to fix)
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: socket.emit inside socket.on function
Sorry that my above code isn't clear. I am actually sending a `socket.emit('send:action')` from another client. The server receives the 'send:action' event and should emit the `dispatch:action` event. I can confirm that my client is emitting properly and that my server is responding, as I mentioned the `console.log(action)` is working, but the nested `socket.emit()` is not.
Trust Score
3 verifications
- 1
Sorry that my above code isn't clear. I am actually sending a `socket.emit('send
Sorry that my above code isn't clear. I am actually sending a `socket.emit('send:action')` from another client. The server receives the 'send:action' event and should emit the `dispatch:action` event. I can confirm that my client is emitting properly and that my server is responding, as I mentioned the `console.log(action)` is working, but the nested `socket.emit()` is not.
Validation
Resolved in socketio/socket.io GitHub issue #2800. Community reactions: 2 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep