Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CLIENT_PORT = {}
- io.write("Set a server port: ")
- SERVER_PORT = tonumber(io.read())
- print("Server port has been set to: "..SERVER_PORT)
- local modem = peripheral.find("modem")
- modem.open(SERVER_PORT)
- function pingLoc()
- io.write("Select a computer to ping: ")
- local num1 = tonumber(io.read())
- modem.transmit(num1, SERVER_PORT, "pingLoc")
- event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
- print(message)
- end
- function clear()
- for i = 1,25 do
- print(" ")
- end
- end
- function list()
- for data in ipairs(CLIENT_PORT) do
- print(" ")
- for value in pairs(data) do
- print(value)
- end
- end
- end
- function help()
- for i = 1,25 do
- print(" ")
- end
- print("loc --Displays the coordinates of requested turtle")
- print("clear --Clears the display")
- print("list --Lists connected computers")
- print("help --Brings up this list")
- end
- function newConnection()
- event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
- if message == "connectMessage" then
- table.insert(CLIENT_PORT, replyChannel, replyChannel)
- print("New connection from "..replyChannel)
- modem.transmit(replyChannel, SERVER_PORT, "connectSuccess")
- end
- end
- function userInput()
- command = io.read()
- end
- while true do
- parallel.waitForAny(newConnection, userInput)
- if command == "loc" then
- pingLoc()
- end
- if command == "list" then
- list()
- end
- if command == "help" then
- help()
- end
- if command == "clear" then
- clear()
- end
- end
- --event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
- --if message == "connectMessage" then
- --print("Connection detected from "..replyChannel)
- --modem.transmit(replyChannel, SERVER_PORT, "connectSuccess")
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement