Skip to content

Conversation

@3rd-Eden
Copy link
Contributor

@3rd-Eden 3rd-Eden commented Aug 7, 2011

Added nodejs support for the client, based on the work of pull req #240

Passes simple test:

var connect = require('connect')
  , app = connect.createServer(connect.static(__dirname))
  , io = require('../../socket.io').listen(app);

io.sockets.on('connection', function (socket) {
  var messages = [];

  socket.on('print', function (msg) {
    if (messages.indexOf(msg) >= 0) {
      console.error('duplicate message', msg);
    }

    messages.push(msg);
    if (messages.length == 2) {
      socket.emit('done');
    }
  });
});

app.listen(8080);

var client = require('../lib/io');

setTimeout(function () {
  var socket = client.connect('http://localhost:8080/')
  socket.on('connect', function () {
    socket.emit('print', 'foo');
    socket.emit('print', 'bar');
  });

  socket.on('connecting', function (transport) {
    console.log('Trying to connect using ' + transport);
  });

  socket.on('disconnect', function () {
    console.log('Aww, disconnected');
  });

  socket.on('reconnecting', function (delay, attempt) {
    console.log('reconnecting, attempt #' + attempt);
  });

  socket.on('reconnect', function () {
    console.log('reconnected <3');
  });

  socket.on('done', function () {
    console.log('done!');
    socket.disconnect();

    process.exit(1);
  });
}, 2000);

rauchg added a commit that referenced this pull request Aug 7, 2011
@rauchg rauchg merged commit 95c8b66 into socketio:master Aug 7, 2011
@bewa
Copy link

bewa commented Aug 8, 2011

Good Job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants