Skip to content

Instantly share code, notes, and snippets.

@jots
Created January 23, 2015 20:49
Show Gist options
  • Save jots/a6a25cba3503b723073a to your computer and use it in GitHub Desktop.
Save jots/a6a25cba3503b723073a to your computer and use it in GitHub Desktop.
net = require "net"
HOST = "127.0.0.1"
createServer = (port) ->
net.createServer((sock) ->
sock.write("welcome! on port #{port}\r\n")
console.log("CONNECTED: #{sock.remoteAddress}:#{sock.remotePort}")
while true # this is the work queue, what ports to send to...
sock.write "hello\r\n"
return
).listen port, HOST
console.log "server listening on #{port}"
return
createServer(7001)
# XXX why does g.on "data" never fire?
# this works fine if I move it into
# it's own file, how to co-exist
# this client with server above
# in same file?
g = net.createConnection(7001, HOST)
g.on "data", (data) ->
console.log "got #{data}"
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment