Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to access websocket clients / handles from websocket server? #60

Open
gittyup2018 opened this issue Mar 11, 2021 · 0 comments
Open

Comments

@gittyup2018
Copy link

gittyup2018 commented Mar 11, 2021

I am new to using websockets with openresty so I apologize if it is documented somewhere but I can't find it and have been trying for several hours unsuccessfully.

is there a way to get and loop through the websocket server handles for each client?

When a new client connects to the server, is there a way to store the socket handle to send a message directly to that socket, or disconnect the socket, etc? I thought I could just store the object in a shared dict but that is for text only and it fails when trying to json encode it:

local json=require("cjson.safe");
local cache=ngx.shared.cache;
local server = require "resty.websocket.server"
local wb, err = server:new{
timeout = 5000,
max_payload_len = 65535
}

local ok,err=json.encode(wb);
if not ok then trace("JSON ERR> " , err);
end;

trace(): JSON ERR> ,*5 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/core/shdict.lua:186: attempt to compare string with number

So how can I save/store the websocket client handle to access it directly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant