User:Ciprian.bacioiu

From MiOS
Revision as of 12:38, 21 November 2016 by Ciprian.bacioiu (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Useful scripts and tools

Luvit server used to receive POST Recordings from HTTP POST enabled sercomm cameras

local http = require("http")
local https = require("https")
local pathJoin = require('luvi').path.join
local fs = require('fs')
 
local function onRequest(req, res)
	local buffer = {}
	print(req.socket.options and "https" or "http", req.method, req.url)
	if req.method == "POST" then
		req:on('data', function(chunk)
			table.insert(buffer, chunk)
			if type(chunk) == "string" then
 
			end
		end)
		req:on('end', function()
			print("Saving video file -------------------------")
			file = io.open("vid-"..os.time()..".avi", "a")
			for i = 1, #buffer do
				print("Completion: "..i.."/"..#buffer.."")
				file:write(""..buffer[i].."")
			end
			file:close()
			print("File saved -------------------------------")
		end)
	end
end
 
 
http.createServer(onRequest):listen(8080)
print("Server listening at http://localhost:8080/")