Wynn Netherland changelog.com/posts

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('./socket.io/socket.io.js'),

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

// socket.io, 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/socket.io.min.js">

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]


Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00