Authorizing and handshaking with Socket.IO

Edit: In Socket.IO 1.0, middleware is now used. Authorization can be done like so: io.use(function(socket, next) { var handshake = socket.request; next(); }); If you were to need to reject the socket, just pass an error object to the next() callback. The same thing can be done with namespaces: io.of(‘/namespace’).use(function(socket, next) { var handshake = … Read more

Socket.io error hooking into express.js

You should use http module: var http = require(‘http’); var express = require(‘express’), app = module.exports.app = express(); var server = http.createServer(app); var io = require(‘socket.io’).listen(server); //pass a http.Server instance server.listen(80); //listen on port 80 //now you can use app and io More details you can find in a documentation: http://socket.io/docs/#using-with-express-3/4

SocketIO ERR_CONNECTION_REFUSED

I faced exactly the same issue. I did not see the ERR_CONNECTION_REFUSED in socket.io@~0.9. The error surfaced after I upgraded socket.io to 1.3. I solved it by simply removing the URL from the client side constructor: Change var socket = io(‘http://localhost’); To var socket = io(); As the socket.io tutorial showed: http://socket.io/get-started/chat/

how to list rooms on socket.io nodejs server

The short answer: io.sockets.adapter.rooms I analysed io: I got the following output: { server: { stack: [ [Object], [Object], [Object], [Object], [Object], [Object] ], connections: 3, allowHalfOpen: true, watcher: { host: [Circular], callback: [Function] }, _events: { request: [Function], connection: [Function: connectionListener], listening: [Object], upgrade: [Object] }, httpAllowHalfOpen: false, cache: {}, settings: { home: “https://stackoverflow.com/”, … Read more