Created
January 23, 2015 20:49
-
-
Save jots/a6a25cba3503b723073a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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