Skip to content

Instantly share code, notes, and snippets.

@aashay
Created September 22, 2012 22:49
Show Gist options
  • Select an option

  • Save aashay/3768121 to your computer and use it in GitHub Desktop.

Select an option

Save aashay/3768121 to your computer and use it in GitHub Desktop.

Revisions

  1. aashay revised this gist Sep 22, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 1 - server.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    /* 1. node server.js */
    var io = require('socket.io').listen(1234);
    io.configure(function () {
    io.set('transports', ['xhr-polling']);
    io.set('transports', ['xhr-polling']);
    });

    io.set('authorization', function(handshakeData, ack) {
  2. aashay revised this gist Sep 22, 2012. No changes.
  3. aashay revised this gist Sep 22, 2012. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  4. aashay created this gist Sep 22, 2012.
    13 changes: 13 additions & 0 deletions client.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    /* 2. node client.js */
    var io = require('socket.io-client');

    var socket = io.connect('http://localhost:1234');
    socket.on("error", function(err){
    console.log(err);
    });
    socket.on('connect', function(message){
    console.log("Connection established!"); //You'll never see this.
    socket.emit("news", "hi");
    });


    8 changes: 8 additions & 0 deletions error
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    // This is the error you'll see after several seconds.

    timers.js:103
    if (!process.listeners('uncaughtException').length) throw e;
    ^
    TypeError: Cannot call method 'onClose' of null
    at Object._onTimeout (/private/tmp/sockettest/node_modules/socket.io-client/lib/socket.js:281:22)
    at Timer.list.ontimeout (timers.js:101:19)
    17 changes: 17 additions & 0 deletions server.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    /* 1. node server.js */
    var io = require('socket.io').listen(1234);
    io.configure(function () {
    io.set('transports', ['xhr-polling']);
    });

    io.set('authorization', function(handshakeData, ack) {
    return ack(null, true);
    });

    io.sockets.on('connection', function (socket) {
    console.log("Someone connected!");

    socket.on("news", function(data){
    console.log(data);
    });
    });