Socket Io Emit
- Code Cheatsheets. Code Cheatsheets. Code Cheatsheets.
- Socket.IO Tutorial With io.js and Express. Socket.IO enables real-time event-based communication. What that means is that we can communicate to the server from the client and in return the server can talk back to the client. Socket.IO uses WebSockets when it can.
- Emit cheatsheet. Io.on ('connection', onConnect); function onConnect(socket). Socket.emit ('hello', 'can you hear me?' , 1, 2, 'abc'); socket.broadcast.emit ('broadcast', 'hello friends!' ); socket.to ('game').emit ('nice game', 'let's play a game'); socket.to ('game1').to ('game2').emit ('nice game', 'let's play a game (too)').
If this is a vague question, please let me know, so that I can specify. I really want to get around this stump. I have read several cheat sheets regarding how to properly broadcast a message to a client room.
socket.js
Socket Io Emit Cheat Sheet Download
io.on('connection',function(socket){ |
/* 'connection' is a special event fired on the server when any new connection is made */ |
}) |
socket.on('disconnect',function(){ |
/* When this individual socket has disconnected, this special event fires */ |
}) |
/* This will send the event 'foobar' with the data to |
every connected to socket */ |
io.emit('foobar',data) |
/* This will send the event 'foobar' with the data object to |
every connected socket EXCEPT for the socket this is called on */ |
socket.broadcast.emit('foobar',data) |
socket.on('foobar',function(data){ |
/* Fires whenever this socket receives an event 'foobar'. |
You can access the data received inside this callback*/ |
}) |
/* This will send the event 'foobar' with the data to the server */ |
socket.emit('foobar',data) |
socket.id// A unique string identifying this socket connection |
Socket Emit
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
