Openresty WebSocket Use

Source: Internet
Author: User

Openresty websocket use 1. The code is as follows:
  1. local server =require"resty.websocket.server"
  2. local wb, err = server:new{
  3. timeout =5000,
  4. max_payload_len =65535
  5. }
  6. ifnot wb then
  7. ngx.log(ngx.ERR,"failed to new websocket: ", err)
  8. return ngx.exit(444)
  9. end
  10. whiletruedo
  11. local data, typ, err = wb:recv_frame()
  12. if wb.fatal then
  13. ngx.log(ngx.ERR,"failed to receive frame: ", err)
  14. return ngx.exit(444)
  15. end
  16. if typ =="close"thenbreak
  17. elseif typ =="text"then
  18. local bytes, err = wb:send_text(data)
  19. ifnot bytes then
  20. ngx.log(ngx.ERR,"failed to send text: ", err)
  21. return ngx.exit(444)
  22. end
  23. end
  24. end
  25. wb:send_close()
2. Reference Document: Https://github.com/openresty/lua-resty-websocket

Openresty WebSocket Use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.