Advertisement
Volaik

asd

Nov 13th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. CLIENT_PORT = {}
  2. io.write("Set a server port: ")
  3. SERVER_PORT = tonumber(io.read())
  4. print("Server port has been set to: "..SERVER_PORT)
  5.  
  6. local modem = peripheral.find("modem")
  7. modem.open(SERVER_PORT)
  8.  
  9. function pingLoc()
  10.     io.write("Select a computer to ping: ")
  11.     local num1 = tonumber(io.read())
  12.     modem.transmit(num1, SERVER_PORT, "pingLoc")
  13.     event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  14.     print(message)
  15. end
  16.  
  17. function list()
  18.     for data in ipairs(CLIENT_PORT) do
  19.         print(" ")
  20.         for value in pairs(data) do
  21.             print(value)
  22.         end
  23.     end
  24. end
  25.  
  26. function newConnection()
  27.     event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  28.     if message == "connectMessage" then
  29.         table.insert(CLIENT_PORT, replyChannel, replyChannel)
  30.         print("New connection from "..replyChannel)
  31.     end
  32. end
  33.  
  34. function userInput()
  35.     command = io.read()
  36. end
  37.  
  38. while true do
  39.     parallel.waitForAny(newConnection, userInput)
  40.     if command == "loc" then
  41.         pingLoc()
  42.     end
  43.     if command == "list" then
  44.         list()
  45.     end
  46. end
  47.  
  48. --event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  49. --if message == "connectMessage" then
  50. --print("Connection detected from "..replyChannel)
  51. --modem.transmit(replyChannel, SERVER_PORT, "connectSuccess")
  52. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement