Advertisement
Volaik

Untitled

Nov 13th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 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 robot 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.  
  40.     parallel.waitForAny(newConnection, userInput)
  41.  
  42.     if command == "loc" then
  43.         pingLoc()
  44.     end
  45.  
  46.     if command == "list" then
  47.         list()
  48.     end
  49. end
  50. --    event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  51. --    if message == "connectMessage" then
  52. --        print("Connection detected from "..replyChannel)
  53. --        modem.transmit(replyChannel, SERVER_PORT, "connectSuccess")
  54. --    end
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement