userlog.lua 541 B

12345678910111213141516171819202122232425
  1. local skynet = require "skynet"
  2. require "skynet.manager"
  3. -- register protocol text before skynet.start would be better.
  4. skynet.register_protocol {
  5. name = "text",
  6. id = skynet.PTYPE_TEXT,
  7. unpack = skynet.tostring,
  8. dispatch = function(_, address, msg)
  9. print(string.format(":%08x(%.2f): %s", address, skynet.time(), msg))
  10. end
  11. }
  12. skynet.register_protocol {
  13. name = "SYSTEM",
  14. id = skynet.PTYPE_SYSTEM,
  15. unpack = function(...) return ... end,
  16. dispatch = function()
  17. -- reopen signal
  18. print("SIGHUP")
  19. end
  20. }
  21. skynet.start(function()
  22. end)