openresty / lua-resty-websocket

WebSocket support for the ngx_lua module (and OpenResty)
508 stars 106 forks source link

Compilation errors while running sample programs https://github.com/openresty/lua-resty-websocket #50

Open Rajasekhar-topgear opened 4 years ago

Rajasekhar-topgear commented 4 years ago

Hi,

I am new to Openresty and Lua programming.

I have installed openresty-1.15.8.3 and dependent libraries pcre-8.40, openssl-1.0.2k, zlib-1.2.11 successfully in Centos7.

I am trying to run server and client programs in the link https://github.com/openresty/lua-resty-websocket but I am getting compilation errors. Could you please let me know what I am missing here.

   PFA the programs ida_client.lua and ida_server.lua.

Errors::

[root@IDA openresty-1.15.8.3]# resty ida_client.lua ERROR: ida_client.lua:3: API disabled in the current context stack traceback: /usr/local/openresty/lualib/resty/core/var.lua:73: in function '__index' ida_client.lua:3: in function 'file_gen' init_worker_by_lua:45: in function [C]: in function 'xpcall' init_worker_by_lua:52: in function [root@IDA openresty-1.15.8.3]# [root@IDA openresty-1.15.8.3]# [root@IDA openresty-1.15.8.3]# [root@IDA openresty-1.15.8.3]# resty ida_server.lua ERROR: /usr/local/openresty/lualib/resty/websocket/server.lua:36: API disabled in the current context stack traceback: /usr/local/openresty/lualib/resty/core/misc.lua:166: in function '__index' /usr/local/openresty/lualib/resty/websocket/server.lua:36: in function 'new' ida_server.lua:3: in function 'file_gen' init_worker_by_lua:45: in function [C]: in function 'xpcall' init_worker_by_lua:52: in function [root@IDA openresty-1.15.8.3]#

Thanks, Rajasekhar

ida_client.txt ida_server.txt

rainingmaster commented 4 years ago

Hi, @Rajasekhar-topgear , you can use a zero-delay timer to raise your connection, just refer to here: https://github.com/openresty/lua-nginx-module#cosockets-not-available-everywhere

Rajasekhar-topgear commented 4 years ago

Hi, @rainingmaster, Thanks a lot for your reply.

 OK, I understood that, "resty" utility is running under context of  "init_worker_by_lua". Cosockets are currently  disabled in "init_worker_by_lua".   So we have to use workaround solution like use a zero-delay timer.

 Other than "resty" utility, can we run the client and server programs using any other way i.e., ngnix like in the example https://openresty.org/en/getting-started.html. 

Something like "nginx -p `pwd`/ -c conf/nginx.conf" in the example. Basically I am trying to find simple way to execute the programs.

 Could you please let me know. 

Thanks, Rajasekhar.

rainingmaster commented 4 years ago

Hi, @rainingmaster, Thanks a lot for your reply.

 OK, I understood that, "resty" utility is running under context of  "init_worker_by_lua". Cosockets are currently  disabled in "init_worker_by_lua".   So we have to use workaround solution like use a zero-delay timer.

 Other than "resty" utility, can we run the client and server programs using any other way i.e., ngnix like in the example https://openresty.org/en/getting-started.html. 

Something like "nginx -p `pwd`/ -c conf/nginx.conf" in the example. Basically I am trying to find simple way to execute the programs.

 Could you please let me know. 

Thanks, Rajasekhar.

Hi, @Rajasekhar-topgear , I think I didn't catch you, do you mean you want to know instead of resty, how to run a Openresty with lua code?

Rajasekhar-topgear commented 4 years ago

Hi @rainingmaster,

1) Yes, instead of resty, how to run Openresty with lua code ?

2) I tried with zero-delay timer as you suggested. I am able to compile the client code but I am getting same error with the server code. PFA the client code and server code.

Server::

[root@IDA openresty-1.15.8.3]# resty ida_server.lua Starting Server 2020/06/26 04:05:15 [error] 9174#0: *3 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/websocket/server.lua:36: API disabled in the current context stack traceback: coroutine 0: [C]: in function 'error' /usr/local/openresty/lualib/resty/core/misc.lua:166: in function '__index' /usr/local/openresty/lualib/resty/websocket/server.lua:36: in function 'new' ida_server.lua:9: in function , context: ngx.timer [root@IDA openresty-1.15.8.3]#

Client::

[root@IDA openresty-1.15.8.3]# resty ida_client.lua Starting Client failed to receive the frame: bad RSV1, RSV2, or RSV3 bits [root@IDA openresty-1.15.8.3]#

ida_client.txt ida_server.txt