Created
December 17, 2011 08:00
-
-
Save ksato9700/1489617 to your computer and use it in GitHub Desktop.
HTTP client and server by node.js
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
var net = require('net') | |
console.log("main") | |
var client = net.connect(8080, function() { | |
console.log("connected") | |
var req_message = "GET / HTTP/1.0\r\n\r\n" | |
client.write(req_message) | |
}); | |
client.on('data', function(data) { | |
console.log("read"); | |
console.log(data.toString()); | |
// client.end(); | |
}); | |
client.on('end', function() { | |
console.log("closed"); | |
}); | |
client.on('error', function(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
var http = require('http'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.write('Hello World\n'); | |
setTimeout(function() { | |
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