On 30/06/2022 11:56, Jürgen Weber wrote:
Hi,

use case: HTML clients connect to @ServerEndpoint, some Servlet.GET
should send a message to connected HTML clients.

I found no other way to have the Servlet have a reference to the
ServerEndpoint than a hack with a static field, as in the Tomcat
sample.

https://github.com/apache/tomcat/blob/3e5ce3108e2684bc25013d9a84a7966a6dcd6e14/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.java

Is there indeed no better way?

Generally, no. You are going to need to do something along those lines.

Depending on the use case, it might be sufficient to have a single Endpoint instance. That would allow the use of instance fields rather than static fields. See section 3.1.78 of the WebSocket 2.1 specification for a description of how to configure the use of a single endpoint instance.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to