Advertisement
Volaik

Server2

Nov 12th, 2021 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. CLIENT_PORT = 0
  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. if CLIENT_PORT == 0 then
  10.     print("I am not broadcasting to anyone")
  11. end
  12.  
  13.  
  14. function pingLoc()
  15.     io.write("Select robot to ping: ")
  16.     local num1 = tonumber(io.read())
  17.     modem.transmit(num1, num1, "pingLoc")
  18. end
  19.  
  20. while true do
  21.  
  22.     event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  23.     if message == "connectMessage" then
  24.         print("Connection detected from "..replyChannel)
  25.         modem.transmit(replyChannel, SERVER_PORT, "connectSuccess")
  26.     end
  27.  
  28.     local command = io.read()
  29.  
  30.     if command == "Loc" then
  31.         pingLoc()
  32.     end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement