Skip to content

Instantly share code, notes, and snippets.

@ksato9700
Created December 17, 2011 08:27
Show Gist options
  • Save ksato9700/1489669 to your computer and use it in GitHub Desktop.
Save ksato9700/1489669 to your computer and use it in GitHub Desktop.
HTTP client and server by coffee-script
net = require 'net'
console.log "main"
client = net.connect 8080, ()->
console.log "connected"
req_message = "GET / HTTP/1.0\r\n\r\n"
client.write req_message
client.on 'data', (data) ->
console.log "read"
console.log data.toString()
# client.end()
client.on 'end', () ->
console.log "closed"
client.on 'error', (exception) ->
console.log exception
http = require 'http'
http.createServer (req, res) ->
res.writeHead 200, 'Content-Type': 'text/plain'
res.write 'Hello World\n'
setTimeout (()-> res.end 'Hello Again\n'), 1000
.listen(8080, "127.0.0.1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment