Node.js restify with socket.io
Asked Answered
M

3

14

Is it possible to run socket.io & restify on the same port like express & socket.io?

I did just like this but it didn't work

# server.coffee
restify = require 'restify'
socket  = require 'socket.io'

server = restify.createServer()

io = socket.listen server
server.listen 1337

when I try to connect to socket.io:

GET http://localhost:1337/socket.io/socket.io.js 404 (Not Found) 
Myrlemyrlene answered 27/10, 2012 at 15:23 Comment(0)
P
25

As suggested here by @jtomasrl and @zacheryph, this worked for me:

var server = restify.createServer();
var io = socketio.listen(server.server); //Note server.server instead of just server
Postmeridian answered 23/5, 2014 at 4:18 Comment(3)
Up 1. Real and helpful answer.Underrate
server.server! ah!Mair
simple and helpfulNeom
K
10

Since this is the first google hit for "restify socket.io" I'm posting a new answer. This works fine now as documented at http://restify.com/docs/home/#socketio

Kalman answered 8/1, 2014 at 23:18 Comment(0)
M
0

Apparently, using socket.io with restify is not possible yet: https://github.com/mcavage/node-restify/issues/230

Mown answered 31/10, 2012 at 1:55 Comment(1)
@Sitapati Das They added the feature, take a look at Socket.IO section: mcavage.github.com/node-restifyEssentialism

© 2022 - 2024 — McMap. All rights reserved.