Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Core
- function modemTimeout(time)
- local timeout = os.startTimer(time)
- while true do
- local ev, p1, p2, p3, p4 = os.pullEvent()
- if ev == 'timer' and p1 == timeout then
- return nil
- elseif ev == 'modem_message' then
- return p1, p2, p3, p4
- end
- end
- end
- function string:split( inSplitPattern, outResults )
- if not outResults then
- outResults = { }
- end
- local theStart = 1
- local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
- while theSplitStart do
- table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
- theStart = theSplitEnd + 1
- theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
- end
- table.insert( outResults, string.sub( self, theStart ) )
- return outResults
- end
- local myIP = 20
- print("Loading com.grimnet.networking")
- print("Connecting to modem")
- local modem = peripheral.wrap('right')
- modem.open(myIP)
- if modem.isOpen(myIP) == true then
- print("Modem Ready")
- end
- local cmd
- while cmd ~= "exit" do
- local raw_cmd = read()
- local cmd_param = raw_cmd:split(" ")
- cmd = cmd_param[0]
- if cmd == "exit" then
- elseif cmd == "ping" then
- local i = read()
- local channel = tonumber(i)
- modem.transmit(channel, myIP, "ping")
- local mS,sC,rC,m = modemTimeout(2)
- if m then
- print("Reply from "..rC.." > "..m)
- else
- print("Message timed out after 2 seconds")
- end
- else
- print("Unknown command: " .. cmd)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement