Advertisement
Volaik

Untitled

Nov 13th, 2021
81
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("ID "..data)
  20.     end
  21. end
  22.  
  23. function newConnection()
  24.     event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  25.     if message == "connectMessage" then
  26.         table.insert(CLIENT_PORT, replyChannel, replyChannel)
  27.         modem.transmit(replyChannel, SERVER_PORT, "connectSuccess")
  28.         print("New connection from "..replyChannel)
  29.     end
  30. end
  31.  
  32. function userInput()
  33.     command = io.read()
  34. end
  35.  
  36. while true do
  37.     parallel.waitForAny(newConnection, userInput)
  38.     if command == "loc" then
  39.         pingLoc()
  40.     end
  41.     if command == "list" then
  42.         list()
  43.     end
  44. end
  45.  
  46. --event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  47. --if message == "connectMessage" then
  48. --print("Connection detected from "..replyChannel)
  49. --modem.transmit(replyChannel, SERVER_PORT, "connectSuccess")
  50. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement