Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. local socket = require("socket")
  2. local json = require("JSON")
  3.  
  4. return {
  5. ["loops"] = {
  6. function()
  7. print("testing!")
  8. local server = assert(socket.tcp())
  9. assert(server:bind("*", 80))
  10. server:listen(5)
  11. local ip, port = server:getsockname()
  12. print("Webhook listener started on IP="..ip..", PORT="..port.."...")
  13. while true do
  14. print("testing!2")
  15. local client,err = server:accept()
  16. if client then
  17. local stuff, err = client:receive("*a")
  18. print(tostring(stuff))
  19. if not err then
  20. local bodyStart = stuff:find("\r\n\r\n", 1, true)
  21. local body = stuff:sub(bodyStart, #stuff)
  22. if(bodyStart and body) then
  23. local decoded = json:decode(body)
  24. if decoded then
  25. print("Received some JSON bullshit!")
  26. print(stuff)
  27. end
  28. end
  29. end
  30. else
  31. print("Error happened while getting a connection! Error: "..tostring(err))
  32. end
  33. client:close()
  34. end
  35. end
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement