openresty / openresty/lua-resty-websocket

how to access websocket clients / handles from websocket server?

Open
#60 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
523
Forks
112
Avg merge
1d 16m
Merged PRs (30d)
2

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the resty.websocket.server module and its server:new entry point, then inspect the repository's documented API and examples. Determine whether client handles can be retained and iterated safely; done means documenting a supported access pattern or explicitly stating that this is unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
backend
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.