Using Socket.io and Express 3.X on the same port
I'm using CoffeeScript. In my opinion, it should replace javascript :)
If you don't think so, you can convert that code to plain javascript here : http://js2coffee.org/
First we have some dependencies :
express = require 'express'
io = require 'socket.io'
http = require 'http'
With Express 3.X you have to explicitely use http and create your server :
server = http.createServer app
io = io.listen server
io.set 'log level', 1
server.listen 80
Now you can manage all your connections :
io.sockets.on 'connection', (socket)->
address = socket.handshake.address
client_ip = address.address
socket.on 'hello',->
socket.emit 'hello_you',
you_are : client_ip
Written by pmaoui
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#