Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js restify with socket.io

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) 
like image 722
Nick Sanders Avatar asked Oct 27 '12 15:10

Nick Sanders


2 Answers

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
like image 136
amolbk Avatar answered Nov 09 '22 12:11

amolbk


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

like image 10
Christopher Dow Avatar answered Nov 09 '22 12:11

Christopher Dow