I've tried using socket.io just like you would with Express, except having it listen on geddy.server
var io = require('socket.io').listen(geddy.server);
That works, as going to /socket.io. brings up the "Welcome to socket.io" page, but the problem occurs when clients' browsers try to load /socket.io/socket.io.js via <script src...></script> It's just simply not found.
I'm assuming it's a routing issue as @mde had mentioned socket routing :)
I'm looking into this one, I'll keep you updated with info as I learn more.
I got Now.js up and running with geddy.
var httpServer = require('http').createServer().listen(8080)
, nowjs = require('now')
, everyone = nowjs.initialize(httpServer);
You can't use geddy.server. Just need to create another one on a different port.
Odd, this should work with the geddy.server; We'll have docs for this soon.
Are there any updates with this issue?
I can use Socket.io on a separate port by doing
geddy.sockets = require('socket.io').listen(4002)
But I would really prefer having it on the same port as the server of course.
Sorry @Hunter-Dolan I haven't had a chance to get to this one yet. I'll see about taking a look at it soon.
What happens when you try to serve socket.io using geddy.server?
No problem. When I try to use geddy.server it is able to serve the "Welcome to socket.io" when you access /socket.io
Afterwards the server worker process will crash.
This is what it shows in the log
[Wed, 27 Jun 2012 22:06:42 GMT] INFO Server worker running in development on port 4000 with a PID of: 2034
info - unhandled socket.io url
throw new Error("Can't set headers after they are sent.");
Error: Can't set headers after they are sent.
at ServerResponse.setHeader (http.js:536:11)
at [object Object].setHeaders (/usr/local/lib/node_modules/geddy/lib/response.js:117:17)
at [object Object].send (/usr/local/lib/node_modules/geddy/lib/response.js:66:10)
at Server.<anonymous> (/usr/local/lib/node_modules/geddy/lib/app.js:551:19)
at Server.emit (events.js:88:20)
at HTTPParser.onIncoming (http.js:1610:12)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:91:29)
at Socket.ondata (http.js:1506:22)
at TCP.onread (net.js:374:27)
[Wed, 27 Jun 2012 22:06:46 GMT] ERROR Worker 2034 died.
I would assume that Socket.io is sending the http headers and content then Geddy is trying to pick it up and route it like a regular page, which of course is causing it to throw an error because the connection is probably already closed.
Thanks for the feedback.
@mde Do you think you could help out with this one? You know the routing/http code better than anyone else I think.
Added try/catch statement to fix issues with Socket.io and Geddy. (Fi…
…xes issue #108)
Alright guys, this is fixed in master right now. I'll let @mde take a look through it and then publish it to npm.
The usage looks like this:
npm install socket.io
You can check out a full example in the examples directory: https://github.com/mde/geddy/tree/master/examples/socket_io
This is just the start of the planned socket.io integration. We're open to ideas on how to make this better, and how to make Geddy and Socket.io work better together.