Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{io} = require './server'
net = require 'net'
{EventEmitter} = require 'events'
EE = new EventEmitter
# TCP/IP
server = net.createServer (client) ->
console.log 'client connected'
client.on 'end', ->
console.log 'client disconnected'
client.on 'error', (error) ->
console.log error
client.on 'data', (data) ->
console.log data.toString()
EE.emit 'data', data.toString()
server.listen 8100
# socket.io
io.sockets.on 'connection', (socket) ->
EE.on 'data', (data) ->
console.log 'data'
socket.emit 'data', data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment