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
95
votes
7 answers

Send additional data on socket connection

How to best send additional data upon socket connection? Client: socket.on('connect',function(){ //I'd like set some values and pass them up to the node server. }); Node.js Server: io.on('connection', function(client){ //I'd like to get the data…
Dan
  • 2,649
  • 4
  • 26
  • 22
92
votes
8 answers

Websocket transport reliability (Socket.io data loss during reconnection)

Used NodeJS, Socket.io Problem Imagine there are 2 users U1 & U2, connected to an app via Socket.io. The algorithm is the following: U1 completely loses Internet connection (ex. switches Internet off) U2 sends a message to U1. U1 does not receive…
igorpavlov
  • 3,576
  • 6
  • 29
  • 56
92
votes
5 answers

Get connection status on Socket.io client

I'm using Socket.io, and I'd like to know the status of connection to the server from the client-side. Something like this: socket.status // return true if connected, false otherwise I need this information to give a visual feedback to the user if…
franzlorenzon
  • 5,845
  • 6
  • 36
  • 58
92
votes
15 answers

Socket.io Client: respond to all events with one handler?

Is it possible to have a socket.io client respond to all events without to have specify each event individually? For example, something like this (which obviously doesn't work right now): var socket = io.connect("http://myserver"); socket.on("*",…
Derick Bailey
  • 72,004
  • 22
  • 206
  • 219
91
votes
7 answers

Sending message to a specific ID in Socket.IO 1.0

I want to sent data to one specific socket ID. We used to be able to do this in the older versions: io.sockets.socket(socketid).emit('message', 'for your eyes only'); How would I go about doing something similar in Socket.IO 1.0?
user2283026
90
votes
21 answers

WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400

I am trying to integrate Socket.io with Angular and I'm having difficulties making a connection from the client-side to the server. I've looked through other related questions but my issue is happening locally, so there's no web server in the…
ashe540
  • 2,041
  • 2
  • 17
  • 17
83
votes
6 answers

Update all clients using Socket.io?

Is it possible to force all clients to update using socket.io? I've tried the following, but it doesn't seem to update other clients when a new client connects: Serverside JavaScript: I'm attempting to send a message to all clients, which contains…
Jack
  • 15,614
  • 19
  • 67
  • 92
83
votes
2 answers

RabbitMQ vs Socket.io?

I'm doing real time live web app development. Browser users should be able to communicate with eachother through a node.js server. One of the user writes a message and all other users will get it. I don't quite get how RabbitMQ works. But from quick…
ajsie
  • 77,632
  • 106
  • 276
  • 381
83
votes
8 answers

Is it possible to use Socket.io with AWS Lambda?

Is it possible to build a function in AWS Lambda that creates a websocket and send data to subscribed applications? Something like this: John has the app SuperPhotoApp opened in his phone but decides to use the desktop browser to upload a photo to…
Vladislav
  • 1,392
  • 1
  • 12
  • 21
81
votes
3 answers

socket.io Removing specific listener

I'm using Socket.io v0.9.16 and Chrome 34 I'm trying to remove a specific listener, or unsubscribe from a specific subscription Something like this: socket.on('testComplete',function(data){ console.log('test complete',data); }); function…
user773737
81
votes
3 answers

Can websocket messages arrive out-of-order?

If we send two messages over the same html5 websocket a split millisecond apart from each other, Is it theoretically possible for the messages to arrive in a different order than they were sent?
Alex Lopatin
  • 965
  • 2
  • 7
  • 8
81
votes
5 answers

Can AngularJS auto-update a view if a persistent model (server database) is changed by an external app?

I'm just starting to familiarize with AngularJS, but I would like to build a web app that has a view that gets auto-upated in real-time (no refresh) for the user when something changes in the server-side database. Can AngularJS handle this (mostly)…
jpeskin
  • 2,801
  • 4
  • 28
  • 27
78
votes
4 answers

Separating file server and socket.io logic in node.js

I'm fairly new to node.js and I've found its quite complicated separating a project into multiple files as the project grows in size. I had one large file before which served as both a file server and a Socket.IO server for a multiplayer HTML5 game.…
stevendesu
  • 15,753
  • 22
  • 105
  • 182
77
votes
4 answers

io.emit vs socket.emit

I'm new to socket.io and have run in to something that seems pretty weird. I don't actually know the difference between socket.emit and io.emit but I can't find an explanation anywhere. io.on('connection', function(socket){ io.emit('connected') …
Manu Masson
  • 1,667
  • 3
  • 18
  • 37
76
votes
8 answers

Where is the socket.io client library?

As far as I have seen, there is no explanation as to where we are to locate the client side script for socket.io if node.js is not used as the web server. I've found a whole directory of client side files, but I need them in a combined version (like…
Braun Shedd
  • 821
  • 1
  • 7
  • 9