Advertisement
Restioson

SecuNet code example

Apr 14th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. -- Load SecuNet api
  2. os.loadAPI("path/to/secunet/installation/secunet/apis/secunet.lua")
  3.  
  4. -- This function will run while a background listener process listens for messages
  5. local function my_script()
  6.  
  7. -- Send a packet to destination_user
  8. secunet.send("Hello there!", "destination_user") -- Replace this with their secunet user id
  9.  
  10. -- Print out any received packet
  11. local sender, message = secunet.receive()
  12.  
  13. print("Got packet from " .. sender .. ": \"" .. message .."\"") -- E.g: Got packet from SecunetUser: "Hello!"
  14.  
  15. -- Disconnect from the server
  16. secunet.disconnect()
  17.  
  18. end
  19.  
  20. -- Port
  21. local port = 4000 -- Default SecuNet port
  22.  
  23. -- Modem side
  24. local modem_side = "top" -- SecuNet's default modem side is top
  25.  
  26. -- Prompt user for login
  27. local username, password = secunet.login()
  28.  
  29. -- Run the listener process while running your script
  30. secunet.mainloop(my_script, username, password, port, modem_side) -- username: Users secunet username. Not necessarily MC username
  31. -- password: User's secunet password
  32. -- modem_side: side modem is on
  33. -- port: port for network packets to be sent to server on.
  34. -- Should be same as server's port. Default is 4000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement