April_The_Sergal

networkManager

Nov 25th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.63 KB | Gaming | 0 0
  1. local function initNetwork(protocol, localID)
  2.     rednet.host(protocol, localID)
  3. end
  4.  
  5. local function handleIncomingMessages()
  6.     while true do
  7.         local senderId, message = rednet.receive(PROTOCOL)
  8.         print("Received message:", textutils.serialize(message))
  9.     end
  10. end
  11.  
  12. local function initiateUpdate(nodes)
  13.     for hostName, node in pairs(nodes) do
  14.         rednet.send(nodeIDs[hostName], { type = "update" }, PROTOCOL)
  15.     end
  16.     print("Update initiated for all nodes.")
  17. end
  18.  
  19. return {
  20.     initNetwork = initNetwork,
  21.     handleIncomingMessages = handleIncomingMessages,
  22.     initiateUpdate = initiateUpdate,
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment