Advertisement
Volaik

swarmServer

Nov 12th, 2021
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.52 KB | None | 0 0
  1. CLIENT_PORT = 0
  2. io.write("Set a server port: ")
  3. SERVER_PORT = io.read()
  4. print()
  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. while true do
  14.     event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  15.     if message == "connectMessage" then
  16.         print("Connection detected from "..senderChannel)
  17.         modem.transmit(senderChannel, SERVER_PORT, "connectSuccess")
  18.     end
  19. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement