Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Client library for Socket.IO for running scripts from node, i.e. introduces io.Socket object

branch: master

io-client magic

latest commit 0202f38881
Remy Sharp authored November 03, 2010
Octocat-spinner-32 example io-client magic November 03, 2010
Octocat-spinner-32 socket.io-node @ 9649b41 io-client magic November 03, 2010
Octocat-spinner-32 .gitmodules io-client magic November 03, 2010
Octocat-spinner-32 README.md io-client magic November 03, 2010
Octocat-spinner-32 io-client.js io-client magic November 03, 2010
README.md

Socket.IO node client

Please note that I'm not the author of Socket.IO - that juicy goodness belongs to LearnBoost

The io-client.js script that allows your client JavaScript that depends on Socket.IO to run in Node. This means that you shuold be able to run your script both on the client side and server side without any modifications.

Example

Where the client side code includes Socket.IO as follows, this shim will allow your client code to also run on the server without any modifications (though assuming you're able to import your code as a module in node):

var socket = new io.Socket('localhost', 8000);

socket.on('connect', function () {
  console.log('yay, connected!');
  socket.send('hi there!');
});

socket.on('message', function (msg) {
  console.log('a new message came in: ' + JSON.stringify(msg));
});

socket.connect();

If the above code was in myapp.js, you can use it in a node app as follows:

var io = require('./io-client').io;
    clientApp = require('./myapp.js');

Now myapp.js will run without any modifications in a node environment.

Note

I've only tested this shim a little bit and it works perfectly to get förbind connecting from the server side. I've not tested broadcasts or multiple messages or message dropping - maybe there's a solution already that I've not spotted!

Something went wrong with that request. Please try again.