Created
December 17, 2011 08:27
-
-
Save ksato9700/1489669 to your computer and use it in GitHub Desktop.
HTTP client and server by coffee-script
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' | |
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 |
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
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