#!/usr/bin/luajit --[[ Minimal web server in Lua. This does run, but it leaves some major things to be desired: - It needs to handle more than one client at a time, for which purpose it needs to set its sockets nonblocking and select or poll on them, perhaps supporting some kind of coroutine-based concurrency. - It needs to parse the HTTP request so that it can handle different requests differently. --]] local salisten = require "salisten" local port = 8051 local server = salisten.server(port) print("listening on http://localhost:"..port) for i = 0, math.huge do local c, ip, port = server:accept() print("connection", ip, port) -- Fennec needs this; if you don't wait -- to read its request, sometimes it -- reports that the connection was closed -- while opening. print(c:read(2048)) c:write("HTTP/1.0 200 Ok\r\n" .. "Content-type: text/html\r\n\r\n" .. [[ My kitty is really hairy. ]]) c:close() end