Skip to content

Instantly share code, notes, and snippets.

@rauchg
Created February 8, 2012 12:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rauchg/8b9bd96888ed8cc0c372 to your computer and use it in GitHub Desktop.
Save rauchg/8b9bd96888ed8cc0c372 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <native/native.h>
using namespace native::http;
int main() {
http server;
if(!server.listen("0.0.0.0", 8080, [](request& req, response& res) {
res.set_status(200);
res.set_header("Content-Type", "text/plain");
res.end("Hello World");
})) return 1; // Failed to run server.
std::cout << "Server listening on http://0.0.0.0:8080/" << std::endl;
return native::run();
}
require('http').createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World');
}).listen(8080, '0.0.0.0', function () {
console.log('Server listening on http://0.0.0.0:8080/');
});
local HTTP = require("http")
HTTP.create_server("0.0.0.0", 8080, function (req, res)
local body = "Hello world"
res:write_head(200, {
["Content-Type"] = "text/plain",
["Content-Length"] = #body
})
res:finish(body)
end)
print("Server listening on http://0.0.0.0:8080/")
@anandgeorge
Copy link

The lua code seems to have a typo at create_server and write_head. Should be createServer and writeHead.

@rphillips
Copy link

luvit just went through a major refactor. camelCase was one of the refactors.

@isaacs
Copy link

isaacs commented Feb 9, 2012

Can you test the node version by generating a buffer up front and sending that, rather than a string?

@anandgeorge
Copy link

Luvit is much faster as per the benchmark test at ab -c 10 -n 10000. However Node.js is stable even at ab -c 1000 -n 100000. Luvit just hangs up even at ab -c 10 -n 10000. The test was on a core i5 with 4GB RAM.

@rphillips
Copy link

Please report any issues to the luvit issue tracker: https://github.com/luvit/luvit/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment