Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local modem = component.modem
- local keyboard = require("keyboard")
- local pullArray = {}
- local DNSAddress = "9955471e-b28f-4001-9d66-79c28c75be2d"
- local address = "0190b137-6ed4-421c-89f0-755193b71c7f"
- local copyArray = {}
- local port = 70
- local timeout = 15
- function OpenModem(port)
- modem.open(port)
- if modem.isOpen(port) then
- print("Successfully opened port " .. port)
- else
- print("Could not open port " .. port .. ", closing server")
- end
- end
- function Quit()
- modem.close(70)
- if modem.isOpen(70) == false then
- print("Successfully closed port 70, closing program...")
- else
- print("Could not close port 70, please contact admin.")
- end
- os.exit()
- end
- function EventPull(timeout)
- local type, _, foreignAddress, port, distance, message = event.pull(timeout)
- local pullArray = {}
- if type == "key_down" then
- if keyboard.isAltDown() then
- Quit()
- end
- elseif type == "modem_message" then
- pullArray[1] = type
- pullArray[2] = foreignAddress
- pullArray[3] = port
- pullArray[4] = distance
- pullArray[5] = message
- --print("Message has been received from DNS on port " .. port)
- end
- return pullArray
- end
- function SendACK(remoteAddress, port)
- modem.send(remoteAddress, port, "ACK")
- --print("ACK has been sent to " .. remoteAddress .. " on port " .. port)
- end
- local function SendTimeout(remoteAddress, port, message, timeout)
- local timeoutPull = {}
- while true do
- modem.send(remoteAddress, port, message)
- timeoutPull = EventPull(timeout)
- if timeoutPull[1] ~= nil then
- break
- end
- end
- end
- OpenModem(port)
- while true do
- pullArray = EventPull(timeout)
- if pullArray[1] == "modem_message" then
- SendACK(pullArray[2], pullArray[3])
- if copyArray[1] ~= pullArray[5] then
- print(pullArray[5])
- end
- copyArray[1] = pullArray[5]
- pullArray = {}
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement