Advertisement
gravitowl

websocket ding :D

Dec 22nd, 2022 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. JSON = (loadfile "json.lua")()
  2.  
  3. local function handleResponse(res)
  4. if (res == nil) then
  5. return
  6. end
  7. if(res.res == "test") then
  8. print("test")
  9. end
  10. end
  11.  
  12. local function main()
  13.  
  14. local ws, err = http.websocket("ws://localhost:3000");
  15. if(ws == false) then
  16. print(err)
  17. return
  18. end
  19.  
  20. while true do
  21. local msg = ws.receive()
  22.  
  23. local json = JSON:decode(msg)
  24. handleResponse(json)
  25. end
  26. end
  27.  
  28. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement