local computer = computer or require("computer") local event = event or require("event") local modem = component.proxy(component.list("modem")()) local function unknown() -- do nothing end local http = {} local http.handlers = setmetatable({}, { __index = function() return unknown end }) local function http.example() http.handlers["/example"] = function (...) -- "modem_message", local addr, remote addr, port, distance, "/example" tmp = {...} modem.send(tmp[3], tmp[4], "hello world") end end local function http.listen(port) modem.open(port) eventID = event.listen("modem_message", function (_, ...) -- event type, local addr, remote addr, port, distance, msg tmp = {...} -- Filter out messages coming from the wrong port if tmp[3] ~= port then return end -- Forward message to the correct handler http.handlers[tmp[5]](tmp) end) return eventID end