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
683
votes
12 answers

Differences between socket.io and websockets

What are the differences between socket.io and websockets in node.js? Are they both server push technologies? The only differences I felt was, socket.io allowed me to send/emit messages by specifying an event name. In the case of socket.io a…
Vivek Mohan
  • 8,078
  • 8
  • 31
  • 49
452
votes
3 answers

Which websocket library to use with Node.js?

Currently there is a plethora of websocket libraries for node.js, the most popular seem to…
balupton
  • 47,113
  • 32
  • 131
  • 182
271
votes
12 answers

Send response to all clients except sender

To send something to all clients, you use: io.sockets.emit('response', data); To receive from clients, you use: socket.on('cursor', function(data) { ... }); How can I combine the two so that when recieving a message on the server from a client,…
switz
  • 24,384
  • 25
  • 76
  • 101
238
votes
12 answers

Send message to specific client with socket.io and node.js

I'm working with socket.io and node.js and until now it seems pretty good, but I don't know how to send a message from the server to an specific client, something like this: client.send(message, receiverSessionId) But neither the .send() nor the…
Rodolfo Palma
  • 2,831
  • 3
  • 16
  • 11
219
votes
17 answers

node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]

[add] So my next problem is that when i try adding a new dependence (npm install --save socket.io). The JSON file is also valid. I get this error: Failed to parse json npm ERR! Unexpected string npm ERR! File: /Users/John/package.json npm ERR!…
209
votes
3 answers

Good beginners tutorial to socket.io?

I am very new to the world of webdevelopment and jumped into the bandwagon because I find the concept of HTML5 very interesting. I am fairly confident on working with canvas and would now like to move over to websockets part of it. I have come to…
Shouvik
  • 11,350
  • 16
  • 58
  • 89
200
votes
35 answers

How do I get a list of connected sockets/clients with Socket.IO?

I'm trying to get a list of all the sockets/clients that are currently connected. io.sockets does not return an array, unfortunately. I know I could keep my own list using an array, but I don't think this is an optimal solution for two…
Andy Hin
  • 30,345
  • 42
  • 99
  • 142
189
votes
7 answers

socket.io rooms or namespacing?

I am investigating nodejs/socket.io for real time chat, and I need some advice for implementing rooms. Which is better, using namespace or using the room feature to completely isolate grops of chatters from each other? what is the real technical…
Joseph
  • 3,085
  • 3
  • 23
  • 33
188
votes
13 answers

node.js, socket.io with SSL

I'm trying to get socket.io running with my SSL certificate however, it will not connect. I based my code off the chat example: var https = require('https'); var fs = require('fs'); /** * Bootstrap app. */ var sys =…
Beyond
  • 2,050
  • 2
  • 13
  • 12
186
votes
6 answers

Maximum concurrent Socket.IO connections

This question has been asked previously but not recently and not with a clear answer. Using Socket.io, is there a maximum number of concurrent connections that one can maintain before you need to add another server? Does anyone know of any active…
Andrew
  • 14,204
  • 15
  • 60
  • 104
172
votes
4 answers

Authenticating socket io connections using JWT

How can I authenticate a socket.io connection? My application uses a login endpoint from another server (python) to get a token, how can I get use that token whenever a user opens a socket connection on the node side? io.on('connection',…
el_pup_le
  • 11,711
  • 26
  • 85
  • 142
170
votes
7 answers

socket.emit() vs. socket.send()

What's the difference between these two? I noticed that if I changed from socket.emit to socket.send in a working program, the server failed to receive the message, although I don't understand why. I also noticed that in my program if I changed from…
node ninja
  • 31,796
  • 59
  • 166
  • 254
158
votes
31 answers

Socket.io + Node.js Cross-Origin Request Blocked

I'm using node and socket.io to write a chat application. It works fine on Chrome but mozilla gives an error to enable the Cross-Origin Requests. Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at…
Waleed Ahmad
  • 2,184
  • 4
  • 21
  • 23
153
votes
12 answers

Using PHP with Socket.io

Is it possible to use Sockets.io on the client side and communicate with a PHP based application on the server? Does PHP even support such a 'long-lived connection' way of writing code? All the sample code I find for socket.io seems to be for…
Yuvi
  • 4,447
  • 8
  • 35
  • 42
148
votes
22 answers

Get the client's IP address in socket.io

When using socket.IO in a Node.js server, is there an easy way to get the IP address of an incoming connection? I know you can get it from a standard HTTP connection, but socket.io is a bit of a different beast.
Toji
  • 33,927
  • 22
  • 105
  • 115
1
2 3
99 100