Advertisement
SuPeRMiNoR3

DNS Test Client

Dec 8th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. fs = require("filesystem")
  2. serial = require("serialization")
  3. component = require("component")
  4. event = require("event")
  5. modem = component.modem
  6.  
  7. function decode(data)
  8. status, result = pcall(serial.unserialize, data)
  9. if status then
  10.  return result
  11. else
  12.  return false
  13. end
  14. end
  15.  
  16. function encode(data)
  17. return serial.serialize(data)
  18. end
  19.  
  20. function send(addr, data)
  21. modem.send(addr, 42, encode(data))
  22. end
  23.  
  24. function broadcast(data)
  25. modem.broadcast(42, encode(data))
  26. end
  27.  
  28. --------------------------------------------
  29.  
  30. modem.open(43)
  31. broadcast({action="register", name="TestClient"})
  32. os.sleep(1)
  33. broadcast({action="lookup", name="TestClient"})
  34.  
  35. e, _, address, port, distance, message = event.pull(5, "modem_message")
  36. message = decode(message)
  37.  
  38. if message.action == "lookup" then
  39.  print(message.response)
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement