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?


public class WSServlet extends HttpServlet

        public static WebSocketRef webSocketRef;


@ServerEndpoint(value = "/broadcast")
public class BroadCastEndpoint
{

        public BroadCastEndpoint()
        {
                WSServlet.webSocketRef = new WebSocketRef();
                WSServlet.webSocketRef.broadCastEndpoint = this;

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

Reply via email to