socket.emit inside socket.on function
See original GitHub issueNote: for support questions, please use one of these channels: stackoverflow or slack
You want to:
- report a bug
- 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)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:22 (2 by maintainers)
Top Results From Across the Web
socket.io emit doesn't work inside socket.on - Stack Overflow
I know the 'fromClient' side is working cause it does print the value of data, but it doesn't print the 'fromServer' value. I'm...
Read more >Emitting events | Socket.IO
IO API is inspired from the Node.js EventEmitter, which means you can emit events on one side ... This also works in the...
Read more >Socket.IO - Event Handling - Tutorialspoint
We can also emit events from the client. To emit an event from your client, use the emit function on the socket object....
Read more >How to use Socket function in io - Javascript - Tabnine
Most used socket functions · Socket.on · Server.on. The event fired when we get a new connection · Socket.emit · Socket.id. The unique...
Read more >Introduction to Sockets.IO in Node.js - GeeksforGeeks
Introduction to Sockets.IO in Node.js · Reliability: It can establishes connection even in the presence of proxies, load-balancers, personal ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
use
io.sockets.emit('news', message)
instead ofsocket.emit
I just started with socket.io and i have no clue if this is the right way to do this. So perhaps some more seasoned socket.io guru can help us.
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 thedispatch:action
event. I can confirm that my client is emitting properly and that my server is responding, as I mentioned theconsole.log(action)
is working, but the nestedsocket.emit()
is not.