iNxmi

socket.lua

Nov 7th, 2023 (edited)
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.57 KB | Gaming | 0 0
  1. local modem = peripheral.find("modem", rednet.open)
  2.  
  3. function getModem()
  4.     return modem
  5. end
  6.  
  7. function send(id, protocol, table)
  8.     local data = textutils.serialize(table)
  9.     rednet.send(id, data, protocol)
  10. end
  11.  
  12. function receive()
  13.     local id, data, protocol = rednet.receive()
  14.     local table = textutils.unserialize(data)
  15.    
  16.     return id, protocol, table
  17. end
  18.  
  19. function request(id, protocol, table)
  20.    send(id, protocol, table)
  21.     return receive()
  22. end
  23.  
  24. return {
  25.     getModem = getModem,
  26.     send = send,
  27.     receive = receive,
  28.     request = request
  29. }
Advertisement
Add Comment
Please, Sign In to add comment