Advertisement
Pampour

Socket.IO Exposed Events

Dec 28th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. SERVER
  2.  
  3. On the server, assuming var io = require('socket.io'),
  4.  
  5. io.sockets.on('connection', function(socket) {}) - initial connection from a client. socket argument should be used in further communication with the client.
  6. socket.on('message', function(message, callback) {}) - "message" is emitted when a message sent with socket.send is received. message is the message sent, and callback is an optional acknowledgement function.
  7. socket.on('anything', function(data) {}) - "anything" can be any event except for the reserved ones.
  8. socket.on('disconnect', function() {}) - the disconnect event is fired in all cases, when the client-server connection is closed. It fires on wanted, unwanted, mobile, unmobile, client and server disconnects. There is no dedicated reconnect event. You have to use the "connection" event for reconnect handling.
  9.  
  10. CLIENT
  11.  
  12. On the client, assuming var socket = io.connect(host, options),
  13.  
  14. socket.on('connect', function () {}) - "connect" is emitted when the socket connected successfully
  15. socket.on('connecting', function () {}) - "connecting" is emitted when the socket is attempting to connect with the server.
  16. socket.on('disconnect', function () {}) - "disconnect" is emitted when the socket disconnected
  17. socket.on('connect_failed', function () {}) - "connect_failed" is emitted when socket.io fails to establish a connection to the server and has no more transports to fallback to.
  18. socket.on('error', function () {}) - "error" is emitted when an error occurs and it cannot be handled by the other event types.
  19. socket.on('message', function (message, callback) {}) - "message" is emitted when a message sent with socket.send is received. message is the sent message, and callback is an optional acknowledgement function.
  20. socket.on('anything', function(data, callback) {}) - "anything" can be any event except for the reserved ones. data is data, and callback can be used to send a reply.
  21. socket.on('reconnect_failed', function () {}) - "reconnect_failed" is emitted when socket.io fails to re-establish a working connection after the connection was dropped.
  22. socket.on('reconnect', function () {}) - "reconnect" is emitted when socket.io successfully reconnected to the server.
  23. socket.on('reconnecting', function () {}) - "reconnecting" is emitted when the socket is attempting to reconnect with the server.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement