Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args={...}
- if #args==0 then
- error("required arguments: monitorName")
- end
- mName=args[1]
- monitor=peripheral.wrap("right")
- rednet.open("left")
- function connect()
- print("connecting to server...")
- while true do
- rednet.broadcast("connectToServer:"..mName,"monitoring")
- msg={rednet.receive("monitoring",1)}
- if msg[1]~=nil then
- id=msg[1] -- id,msg,distance,protocol
- if msg[2]=="successfullyConnected" then
- print("successfully connected to server")
- return id
- else
- error("unknown message: "..msg[2])
- end
- end
- end
- end
- function len(txt)
- return #txt
- end
- function ping()
- i=0
- while i<3 do
- rednet.send(host,"ping","monitoring")
- msg={rednet.receive("monitoring",1)}
- if msg[1]~=nil then
- return true
- end
- i=i+1
- end
- return false
- end
- host=connect()
- while true do
- if ping()==false then
- print("ping failed")
- host=connect()
- end
- msg={rednet.receive("monitoring",1)}
- if msg[1]~=nil then
- print(msg[2])
- if msg[2]:sub(1,len("displayMsg:"))=="displayMsg:" then
- txt=msg[2]:sub(len("displayMsg:")+1)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write(txt)
- else
- print("unknown message: "..msg[2])
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement