Advertisement
Sanwiches

Switch/LAN Router

Jan 16th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. local function createFile(name,content)
  2. if fs.exists(name) then
  3. return "file exists"
  4. else
  5. local file = fs.open(name, "w")
  6. file.write(content)
  7. file.flush()
  8. end
  9. print("Created file "..name)
  10. end
  11.  
  12. local function listenSwitch()
  13. -- Listen to switch
  14. switch.open(channel)
  15. while true do
  16. local event, modemSide, senderID, channel, message = os.pullEvent("modem_message")
  17. if modemSide == switchSide then
  18. modem.transmit(channel, channel, message)
  19. print(textutils.serialize(message))
  20. end
  21. end
  22. end
  23.  
  24. local function listenModem()
  25. -- Listen to modem
  26. modem.open(channel)
  27. while true do
  28. local event, modemSide, senderID, channel, message = os.pullEvent("modem_message")
  29. if modemSide == wiredSide then
  30. switch.transmit(channel, channel, message)
  31. print(textutils.serialize(message))
  32. end
  33. end
  34. end
  35.  
  36. switchSide = "left"
  37. wiredSide = "right"
  38. switch = peripheral.wrap(switchSide)
  39. modem = peripheral.wrap(wiredSide)
  40. channel = 65535
  41.  
  42. parallel.waitForAny(listenModem, listenSwitch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement