I am trying to connect /node.js to work together beautifully and simply. I have the following (in coffeescript)
connect = require('connect') io = require('socket.io') server = connect.createServer( connect.favicon() , connect.logger() , connect.static(__dirname + '/public') ).listen(8000) socket = io.listen(server) socket.on 'connection', (socket) -> socket.send({ hello: 'world' })
But keep getting the following error:
TypeError: Cannot call method 'listeners' of undefined
It seems that the server is not initializing in time for the socket to start listening.
Compare with:
io = require ("socket.io") http = require('http') server = http.createServer() server.listen(8000) socket = io.listen(server) socket.on 'connection', (socket) -> socket.send({ hello: 'world' })
What works...
source share