Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local serialization = require("serialization")
- local term = require("term")
- local text = require("text")
- local thread = require("thread")
- local listenPort = 55
- function messageReceived(event, localAddress, removeAddress, port, distance, message)
- if distance > 0 then
- print("Message received: " .. message)
- local t = serialization.unserialize(message)
- for k in pairs(t) do
- print(k .. ": " .. tostring(t[k] or ""))
- end
- end
- end
- function main()
- -- Attach event listener to modem
- component.modem.open(listenPort)
- event.listen("modem_message", messageReceived)
- -- Read user input
- while true do
- userInput = text.trim(term.read())
- if userInput == "exit" or userInput == "quit" then
- break
- end
- end
- end
- -- Wait for main thread to exit, or interrupt signal (^C)
- thread.waitForAny({
- thread.create(main),
- thread.create(function() event.pull("interrupted") end)
- })
- term.clear()
- os.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment