Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- endpoint = "http://[::1]:8092/".. os.getComputerID()
- http.request(endpoint)
- modem = peripheral.wrap("top")
- if modem ~= nil then
- modem.open(rednet.CHANNEL_REPEAT)
- end
- local running = true
- while running do
- local event, url, sourceText, rc, msg = os.pullEvent()
- if event == "http_success" then
- local response = sourceText.readAll()
- sourceText.close()
- if response ~= "" then
- print(response)
- local t = textutils.unserialize(response)
- if t ~= nil then
- print("Sending to "..t.msg.nRecipient)
- modem.transmit(t.msg.nRecipient,t.rc,t.msg)
- end
- end
- http.request(endpoint)
- elseif event == "http_failure" then
- print("Lost communication with endpoint")
- modem.close(rednet.CHANNEL_REPEAT)
- running = false
- elseif event == "modem_message" then
- print("Relaying from "..rc)
- t = {}
- t.rc = rc
- t.msg = msg
- http.post(endpoint,textutils.serialize(t))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement