Connect / node.js - creating a simple server -
i'm trying connect / node.js work nicely , simply. have 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 following error:
typeerror: cannot call method 'listeners' of undefined
it seems server not being initialized in time socket 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' })
which work...
probably because .listen()
returns else. should work if rewrite code this:
connect = require('connect') io = require('socket.io') server = connect.createserver( connect.favicon() , connect.logger() , connect.static(__dirname + '/public') ) server.listen(8000) socket = io.listen(server) socket.on 'connection', (socket) -> socket.send({ hello: 'world' })
Comments
Post a Comment