JavaScript Icon

Socket.IO - multi-transport socket server for Node.js

Socket.IO from RosePad is a web sockets server for Node.js that supports a number of transport options including:

  • WebSocket (with Flash policy support)
  • Server-Sent Events
  • XHR Polling
  • XHR Multipart Streaming
  • Forever Iframe

To create a socket, create by creating your server and instructing Socket.IO to listen:

var http = require('http'), 
        io = require('./'),

server = http.createServer(function(req, res){
    // your normal server code
    res.writeHeader(200, {'Content-Type': 'text/html'});
    res.writeBody('<h1>Hello world</h1>');

//, I choose you

In the browser, you’ll need the Socket.IO client. First include the minified version and configure Socket.IO with the path to your server:

<script src="/path/to/">

Once configured, you can send data and wire up callbacks when Socket.IO receives data from the server:

socket = new io.Socket('localhost');
socket.send('some data');
socket.addEvent('message', function(data){
    alert('got some data' + data);

[Source on GitHub] [Client on GitHub]

0:00 / 0:00