Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap('back')
- function send(chan,reply,m)
- modem.transmit(chan,reply,m)
- end
- function get(chan,tmout)--listener
- if tmout==nil then
- tmout=100000000000000000000000000000 --change to call event w/o timer
- end
- modem.open(chan) --opens port
- chk=modem.isOpen(chan) --checks to make sure it is open
- if chk==true then --will set listener
- --mm = os.pullEvent("modem_message")
- timeout = os.startTimer(tmout)
- while true do
- event = {os.pullEvent()}
- if event[1] == "modem_message" then
- --print'Worked'
- --print(event[1].." "..event[2].." "..event[3].." "..event[4].." "..event[5].." "..event[6])
- msg=event[5]
- returnchan=event[4]
- chan=event[3]
- break
- elseif event[1] == "timer" and event[2] == timeout then
- break
- end
- end
- end
- if chk==false then
- --send error# to screen
- print('Error 100: Failed to Bind Port '..chan..'.')
- end
- end
- function listen()
- print'Listening...'
- while true do
- get(1)
- --print(msg)
- send(2,1,"ping")
- --sleep(.5)
- --os.reboot()
- end
- end
- function test()
- print'Welcome to Server 1.'
- print'System online.'
- print'Please make a choice:'
- print'1: Shutdown'
- print'2: Reboot'
- print'3: Terminate'
- ch=io.read()
- ch=ch+1-1
- if ch==1 then
- print'Shutting down!'
- sleep(1)
- os.shutdown()
- end
- if ch==2 then
- print'Rebooting!'
- sleep(1)
- os.reboot()
- end
- if ch==3 then
- print'Terminating program!'
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- end
- end
- parallel.waitForAny(test,listen)
Advertisement
Add Comment
Please, Sign In to add comment