我正在尝试从 Jetty 9.4 迁移到 Jetty 11(可能太早了?),但未能调整用于设置 websockets 的代码。我在 9.4 中实现这一点的方法如下:
Server server = new Server();
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSendServerVersion(false);
HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig);
ServerConnector httpConnector = new ServerConnector(server, httpFactory);
httpConnector.setPort(port);
server.setConnectors(new Connector[] { httpConnector });
// Setup the basic application "context" for this application at "/"
// This is also known as the handler tree (in jetty speak)
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
// Add a websocket to a specific path spec
ServletHolder holderEvents2 = new …Run Code Online (Sandbox Code Playgroud)