Advertisement
Bjornir90

Secure channel switch

Feb 10th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. --I assume the modem is on the top
  2. local modem = peripheral.wrap("top")
  3. local channel = 1
  4. modem.open(channel)
  5.  
  6.  
  7.  
  8. --Put your networking things here
  9.  
  10.  
  11. local newChannel = math.random(1, 65535)
  12. modem.transmit(actualChannel, actualChannel, "#/switch#")
  13. modem.transmit(actualChannel, actualChannel, tostring(newChannel))
  14. modem.close(actualChannel)
  15. modem.open(newChannel)
  16. local actualChannel = newChannel
  17.  
  18. --On the receiving computer
  19.  
  20. while true do
  21.  local messageT = {os.pullEvent("modem_message")}
  22.  if messageT[4] == "#/switch#" then
  23.   local messageS = {os.pullEvent("modem_message")}
  24.   local newChannel = tonumber(messageS[4])
  25.   modem.close(actualChannel)
  26.   modem.open(newChannel)
  27.   actualChannel = newChannel
  28.  end
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement