本文整理汇总了Java中org.eclipse.jetty.websocket.WebSocketHandler类的典型用法代码示例。如果您正苦于以下问题:Java WebSocketHandler类的具体用法?Java WebSocketHandler怎么用?Java WebSocketHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketHandler类属于org.eclipse.jetty.websocket包,在下文中一共展示了WebSocketHandler类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: WebSocketServer
import org.eclipse.jetty.websocket.WebSocketHandler; //导入依赖的package包/类
public WebSocketServer(int port, String rootDirPath, final MainWindow m, final Statement smt, final java.sql.Connection sqlcon) {
idCounter = 0;
connector = new SelectChannelConnector();
connector.setPort(port);
addConnector(connector);
wsHandler = new WebSocketHandler() {
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request,
String protocol) {
idCounter++;
System.out.printf("Protocol:%s\n", protocol);
return new MyWebSocket(idCounter, m, smt, sqlcon);
}
};
resHandler = new ResourceHandler();
resHandler.setDirectoriesListed(true);
resHandler.setResourceBase(rootDirPath);
wsHandler.setHandler(resHandler);
setHandler(wsHandler);
}
开发者ID:ryohashioka,项目名称:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House,代码行数:25,代码来源:WebSocketServer.java
示例2: start
import org.eclipse.jetty.websocket.WebSocketHandler; //导入依赖的package包/类
@Override
public void start() {
SelectChannelConnector wsConnector = new SelectChannelConnector();
wsConnector.setHost(listenAddress);
wsConnector.setPort(listenPort);
wsConnector.setName("webSocket");
wsConnector.setThreadPool(new QueuedThreadPool(10));
server.setConnectors(new Connector[] { wsConnector });
server.setHandler(new WebSocketHandler() {
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request,
String protocol) {
log.debug("Request path:" + request.getRequestURI());
String beanName = request.getRequestURI().replaceFirst("\\/",
"");
final WebsocketHandler handler = applicationContext.getBean(
beanName, WebsocketHandler.class);
return new WebSocket.OnTextMessage() {
@Override
public void onOpen(Connection connection) {
connection.setMaxIdleTime(3600000);
handler.setConnection(connection);
handler.start();
}
@Override
public void onClose(int code, String message) {
handler.stop();
log.info("Connection closed.");
}
@Override
public void onMessage(String data) {
handler.postMessage(data);
}
};
}
});
serverThread.execute(new Runnable() {
@Override
public void run() {
try {
server.start();
server.join();
} catch (Exception e) {
log.warn(e.getMessage(), e);
}
}
});
}
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:58,代码来源:WebSocketListener.java
注:本文中的org.eclipse.jetty.websocket.WebSocketHandler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论