Questions tagged [socket.io]

Socket.IO aims to make real-time apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. It supports multiple transports, such as WebSockets, Flash sockets, long polling, and more, automatically falling back when a transport fails.

Socket.IO is a Node.js package designed to make real-time applications possible and easy in every browser and mobile device. It supports the following transport mechanisms:

  • WebSockets
  • Adobe® Flash® Socket
  • AJAX long polling
  • AJAX multipart streaming
  • Forever Iframe
  • JSONP Polling

Socket.IO includes a JavaScript library that allows for easy programmatic communication with the server.

Some interesting Socket.IO features include:

  • Automatic JSON serialization
  • Namespacing connections over a single multiplexed connection
  • Volatile messages
  • Rooms (logically grouped connections)

API documentation can be found on the project's Wiki.

Useful Links:

20688 questions
136
votes
18 answers

force client disconnect from server with socket.io and nodejs

Is there any way to disconnect a client with SocketIO, and literally close the connection? So if someone is connected to my server, and I want to close the connection between them and my server, how would I go about doing that?
Daniel Kenney
  • 1,493
  • 2
  • 10
  • 10
135
votes
7 answers

Node.js client for a socket.io server

I have a socket.io server running and a matching webpage with a socket.io.js client. All works fine. But, I am wondering if it is possible, on another machine, to run a separate node.js application which would act as a client and connect to the…
Predrag Stojadinović
  • 3,439
  • 6
  • 34
  • 52
134
votes
7 answers

Socket.IO Authentication

I am trying to use Socket.IO in Node.js, and am trying to allow the server to give an identity to each of the Socket.IO clients. As the socket code is outside the scope of the http server code, it doesn't have easy access to the request information…
Ryan
  • 2,102
  • 4
  • 18
  • 23
132
votes
14 answers

WebSockets and Apache proxy: how to configure mod_proxy_wstunnel?

I have : Apache 2.4 on port 80 of my server, with mod_proxy and mod_proxy_wstunnel enabled Node.js + socket.io on port 3001 of the same server Accessing example.com (with port 80) redirects to 2. thanks to this method with the following Apache…
Basj
  • 41,386
  • 99
  • 383
  • 673
124
votes
5 answers

What is an example of the simplest possible Socket.io example?

So, I have been trying to understand Socket.io lately, but I am not a supergreat programmer, and almost every example I can find on the web (believe me I have looked for hours and hours), has extra stuff that complicates things. A lot of the…
Cocorico
  • 2,319
  • 3
  • 22
  • 31
120
votes
5 answers

Socket.io rooms difference between broadcast.to and sockets.in

Socket.io's readme contains the following example: var io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { socket.join('justin bieber fans'); socket.broadcast.to('justin bieber fans').emit('new…
knex
  • 1,733
  • 3
  • 15
  • 11
120
votes
8 answers

How to send a message to a particular client with socket.io

I'm starting with socket.io + node.js, I know how to send a message locally and to broadcast socket.broadcast.emit() function:- all the connected clients receive the same message. Now, I would like to know how to send a private message to a…
Nizar B.
  • 3,098
  • 9
  • 38
  • 56
118
votes
4 answers

What's the difference between io.sockets.emit and broadcast?

What's the difference between io.sockets.emit and socket.broadcast.emit? Is it only that broadcast emits to everyone BUT the socket that sends it? It seems like they can be used interchangeably: io.sockets.on('connection', function (socket) { …
swiecki
  • 3,483
  • 3
  • 23
  • 19
110
votes
2 answers

How to remove debugging from an Express app?

I would like to remove the debugging mode. I am using express, redis, socket.io and connect-redis, but I do not know where the debugging mode comes from. Someone has an idea?
Vsplit
  • 1,988
  • 3
  • 15
  • 18
106
votes
4 answers

Socket.IO handling disconnect event

Can't handle this disconnect event, don't know why socket is not sent to the client / client doesn't respond! Server io.sockets.on('connection', function (socket) { socket.on('NewPlayer', function(data1) { online = online + 1; …
Raggaer
  • 3,244
  • 8
  • 36
  • 67
103
votes
3 answers

Faye vs. Socket.IO (and Juggernaut)

Socket.IO seems to be the most popular and active WebSocket emulation library. Juggernaut uses it to create a complete pub/sub system. Faye is also popular and active, and has its own javascript library, making its complete functionality comparable…
John Bachir
  • 22,495
  • 29
  • 154
  • 227
100
votes
7 answers

How to share sessions with Socket.IO 1.x and Express 4.x?

How can I share a session with Socket.io 1.0 and Express 4.x? I use a Redis Store, but I believe it should not matter. I know I have to use a middleware to look at cookies and fetch session, but don't know how. I searched but could not find any…
Mustafa
  • 10,013
  • 10
  • 70
  • 116
99
votes
11 answers

socket.io and session?

I'm using express framework. I want to reach session data from socket.io. I tried express dynamicHelpers with client.listener.server.dynamicViewHelpers data, but i can't get session data. Is there a simple way to do this? Please see the…
sfs
  • 1,133
  • 2
  • 9
  • 9
97
votes
3 answers

How to integrate nodeJS + Socket.IO and PHP?

I have recently been looking around, to find a good way to communicate between nodeJS and PHP. Here is the idea : nodeJS is still quite new, and it can be kind of tricky to develop a full application only with it. Moreover, you may need it only for…
Jérémy Dutheil
  • 6,099
  • 7
  • 37
  • 52
96
votes
8 answers

Using socket.io in Express 4 and express-generator's /bin/www

So here is the deal: I'm trying to use socket.io in an express project. After Express Js 4 was lauched, i've updated my express-generator and now the app initial functions goes into ./bin/www file, including those vars (www file contents:…
user1576978
  • 1,763
  • 1
  • 14
  • 27