socket.io compatibility #230

Closed
alvarolm opened this Issue Oct 15, 2012 · 21 comments

Comments

Projects
None yet
10 participants

I haven't found yet any about, would be nice :)

Contributor

mcavage commented Oct 21, 2012

Yeah, I looked at it a long time ago, but frankly nobody was asking for it, so I just never did it. It would be nice, although the masses are pretty clear they'd like zip first ;)

+1

this works

socketIO.listen(server.server)

This probably isnt the most proper way to handle this BUT you can do the following:

serv = restify.createServer();
io.listen(serv.server);
Contributor

mcavage commented Oct 31, 2012

Since there's clearly interest in this, I'm actually curious if you folks looking for it could give me some input of what you it to act like? Is this purely because you want the restify server on port XXXX to also serve socket.io requests on the same port? Or, something else?

for me works just perfect, I wanted the restify server on the same port as socket.io

Contributor

mcavage commented Oct 31, 2012

As in the example from @zacheryph is all you're looking for?

I think this throws people off since its a bit different than express/connect. express extends connect which extends node's HTTPServer (albeit in a little convoluted way) so the express app itself is the http server. though restify is wrapping the server and 'hiding' it from the user.

It might be beneficial to look at changing restify to extend node's HTTPServer as appose to wrapping it, that or making it maybe a little more obvious in the wiki/docs for how to get to the raw server for these purposes (though its not that hard to find looking at the source)

just a few pennies in the jar. i haven't had the opportunity to use restify yet myself :x

mavrick commented Nov 1, 2012

@mcavage correct, if you can support socket.io to run on the same port as the restify server (same as express support for socket.io) then you will make a lot of people happy :D

melkior commented Nov 1, 2012

+1

Contributor

mcavage commented Nov 1, 2012

Ok, I hacked this some last night - shouldn't be hard to get it "suitable". I'll make sure this is included in restify 2.0.

I should note how i commented is how express 2 works. I'm pretty sure express 3 works the same way as socket.io does in which you manually create the http server and give express the http server to bind too.

tamsler commented Nov 10, 2012

+1

tamsler commented Nov 16, 2012

When will you release restify v2.0?

Contributor

mcavage commented Nov 16, 2012

Realistically given my day job schedule, sometime mid-late december.

On Fri, Nov 16, 2012 at 2:18 PM, Thomas Amsler notifications@github.comwrote:

When will you release restify v2.0?


Reply to this email directly or view it on GitHubhttps://github.com/mcavage/node-restify/issues/230#issuecomment-10464523.

@ghost

ghost commented Nov 17, 2012

I also consider using restify but I ask myself how to use restify if I have a running node server which serves my static files and want to use this node to run a REST api with restify? Or in other words, is there no way to get restify hook into an existing node rather than opening a dedicated server instance?

tamsler commented Nov 26, 2012

How does the client access "socket.io/socket.io.js" via restify?

@tamsler this is handled by socket.io when it is attached to the http server.

as far as i understand it, the way express 3 works is you give it the http server to 'attach' to, like socket.io does, socket.io handles adding routes to the http server to respond to.

tamsler commented Dec 1, 2012

@zacheryph You are correct. Socket.io adds routes for /socket.io.

@mcavage mcavage pushed a commit that referenced this issue Dec 16, 2012

Mark Cavage #230: first class socket.io 631662b
Contributor

mcavage commented Dec 16, 2012

Ok, this is in #master now - there's an example server in /examples. Anybody want to validate?

mcavage closed this Dec 16, 2012

euskode commented Jan 14, 2013

I can't seem to get it to work. @mcavage what do you mean by "just treat your restify server as if it were a "raw" node server"? I get what you mean by the example, but that is not how I use restify, so I am wondering if that is a requirement in some way. When I attempt to connect to socket.io listening on the same port as restify, I get 404s.

This does not work with a non default 'resource'. e.g.

// client
var socket = io.connect('http://localhost:9080', { resource: 'myspecial/socket.io' });

// server
 var io = socketio.listen(server, {
            'resource': '/myspecial/socket.io', 
        }); 

Works fine the native http server.

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