Skip to content

Instantly share code, notes, and snippets.

@getify
Created October 5, 2011 04:07
Show Gist options
  • Save getify/1263609 to your computer and use it in GitHub Desktop.
Save getify/1263609 to your computer and use it in GitHub Desktop.
trouble getting socket.io to work in node
xx.yy.zz.ww GET 200 application/javascript 234B 72ms
278839520115563000 GET 101 undefined 30B 2.0min
278839520115563000 GET 200 text/plain 159B 2.3min
278839520115563000 GET 200 text/javascript 166B 20.40s
278839520115563000 GET 200 text/javascript 166B 20.06s
278839520115563000 GET 200 text/javascript 166B 20.07s
278839520115563000 GET 200 text/javascript 166B 20.08s
278839520115563000 GET 200 text/javascript 166B 20.07s
278839520115563000 GET (failed) undefined 30B 1.6min
278839520115563000 GET 200 text/plain 159B 20.09s
278839520115563000 GET 200 text/plain 159B 20.12s
278839520115563000 GET 200 text/plain 159B 20.06s
278839520115563000 GET (canceled) undefined 30B 5.03s
var socket = io.connect("http://xx.yy.zz.ww");
socket.on('news', function(data,success){
console.log("DATA!");
success("yes");
});
//socket.emit('my other event', { my: 'data' });
info - socket.io started
debug - served static /socket.io.js
debug - client authorized
info - handshake authorized 278839520115563206
debug - setting request GET /socket.io/1/websocket/278839520115563206
debug - set heartbeat interval for client 278839520115563206
debug - client authorized for
debug - websocket writing 1::
connection established!
debug - websocket writing 5:1+::{"name":"news","args":[{"hello":"world"}]}
debug - setting request GET /socket.io/1/xhr-polling/278839520115563206?t=1317787153942
debug - setting poll timeout
debug - discarding transport
debug - cleared heartbeat interval for client 278839520115563206
debug - setting request GET /socket.io/1/jsonp-polling/278839520115563206?t=1317787164043&i=1
debug - setting poll timeout
debug - discarding transport
debug - clearing poll timeout
debug - clearing poll timeout
debug - jsonppolling writing io.j[1]("8::");
debug - set close timeout for client 278839520115563206
debug - jsonppolling closed due to exceeded duration
debug - setting request GET /socket.io/1/jsonp-polling/278839520115563206?t=1317787184457&i=1
debug - setting poll timeout
debug - discarding transport
debug - cleared close timeout for client 278839520115563206
debug - clearing poll timeout
debug - jsonppolling writing io.j[1]("8::");
debug - set close timeout for client 278839520115563206
debug - jsonppolling closed due to exceeded duration
debug - setting request GET /socket.io/1/jsonp-polling/278839520115563206?t=1317787204519&i=1
debug - setting poll timeout
debug - discarding transport
debug - cleared close timeout for client 278839520115563206
debug - clearing poll timeout
var app = require('http').createServer(function(req, res){
res.writeHead(200);
res.end("Nothing to see here, folks.");
}),
io = require('/usr/local/lib/node_modules/socket.io').listen(app)
;
app.listen(80, "xx.yy.zz.ww");
io.configure(function(){
io.enable('browser client minification'); // send minified client
io.enable('browser client etag'); // apply etag caching logic based on version number
// io.set('log level', 1); // reduce logging
io.set('transports', [ // enable all transports (optional if you want flashsocket)
'websocket'
, 'flashsocket'
, 'htmlfile'
, 'xhr-polling'
, 'jsonp-polling'
]);
});
io.sockets.on('connection', function (socket) {
console.log("connection established!");
//socket.on('my other event', function (data) {
// console.log("DATA:"+data);
//});
socket.emit('news', { hello: 'world' }, function(data) {
console.log("received:"+data);
});
});
@getify
Copy link
Author

getify commented Oct 5, 2011

the "connection established!" is fired on the server, but not in the client. And you can see the server tries to send the message out to the client, but it never receives it.

@getify
Copy link
Author

getify commented Oct 5, 2011

updated to take out the client.js on-connect wrapper... still, server sends out "news" message, but client never receives it.

@groovecoder
Copy link

not sure if you're still fighting this, but did you try socket.on('message')?

@groovecoder
Copy link

Also, with my socket.io 0.8.4 app I don't use a node http server - I skip it and use just a socket.io server:

#!/usr/bin/env node
var io = require('socket.io').listen(8080);
io.sockets.on('connection', function(socket){
// blah
});

@getify
Copy link
Author

getify commented Oct 6, 2011

I've tried "on-message" and it still doesn't work. I even tried it where it's same-domain, and still it won't work.

i'm convinced it's something about my server setup, but for the life of me i can't figure out what.

@groovecoder
Copy link

sorry man, I'm out of ideas. :(

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