socket.io private message

No tutorial needed. The Socket.IO FAQ is pretty straightforward on this one: socket.emit(‘news’, { hello: ‘world’ }); EDIT: Folks are linking to this question when asking about how to get that socket object later. There is no need to. When a new client connects, save a reference to that socket on whatever object you’re keeping … Read more

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

How to connect two node.js servers with websockets?

For future people: Here is 2 very simple Node.js apps that use socket.io to connect, send and receive messages between each other. Required package is: npm install socket.io Node-App-1 server.js: var io = require(‘socket.io’).listen(3000); io.on(‘connection’, function (socket) { console.log(‘connected:’, socket.client.id); socket.on(‘serverEvent’, function (data) { console.log(‘new message from client:’, data); }); setInterval(function () { socket.emit(‘clientEvent’, Math.random()); … Read more

Unit testing Node.js and WebSockets (Socket.io)

After further poking and prodding, I found some incredibly useful information. In the author’s example, he points out the critical step of establishing socket listeners in the before hooks. This example works: Assuming a server is listening for socket connections at localhost:3001, of course var io = require(‘socket.io-client’) , assert = require(‘assert’) , expect = … Read more

socket.io and express 4 sessions

Here’s my solution for the following environment: express 4.2.0 socket.io 1.1.0 cookie-parser 1.0.1 cookie-session 1.0.2 Code: var cookieParser = require(‘cookie-parser’)(); var session = require(‘cookie-session’)({ secret: ‘secret’ }; … app.use(cookieParser); app.use(session); … io.use(function(socket, next) { var req = socket.handshake; var res = {}; cookieParser(req, res, function(err) { if (err) return next(err); session(req, res, next); }); }); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)