sha*_*her 6 java java-websocket
所以我有一个Websocket Session,它从服务器读取信息.但是,如果我切断了它完全接收的信息,大约一分钟后它将停止接收新信息,并且即使重新打开服务器的输出也不会做任何事情.
我以为是WebSocketContainer方法
setDefaultMaxSessionIdleTimeout(Long time)
Run Code Online (Sandbox Code Playgroud)
会解决我的问题,所以我把它设置为
container.setDefaultMaxSessionIdleTimeout(86400000L);
Run Code Online (Sandbox Code Playgroud)
我认为这意味着它将继续运行长达1天的不活动状态.
然而事实并非如此,它在一分钟不活动后就停止了.下面是我正在使用的代码,也许有人可以让我知道我做错了什么:
public void run(String... args) throws Exception {
log.info("Starting...");
log.info("-- API URL: {}", apiUrl);
log.info("-- API Token: {}", apiToken);
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container.setDefaultMaxSessionIdleTimeout(86400000L);
ClientEndpointConfig config = ClientEndpointConfig
.Builder.create()
.configurator(new CustomConfigurator(apiToken))
.build();
try {
session = container.connectToServer(ConsumerClient.class, config, URI.create(apiUrl));
} catch (DeploymentException de) {
log.error("Failed to connect - DeploymentException:", de);
} catch (IOException ioe) {
log.error("IOException:", ioe);
}
if (this.session == null) {
throw new RuntimeException("Unable to connect to endpoint.");
}
log.info("Max Idle Timeout: " + session.getMaxIdleTimeout());
log.info("Connected.");
log.info("Type \"exit\" to cancel.");
log.info("...Waiting for data...");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input;
try {
do {
input = br.readLine();
if (!input.equals("exit")) {
this.session.getBasicRemote().sendText(input);
}
} while (!input.equals("exit"));
} catch (IOException e) {
log.error("IOException:", e);
}
}
Run Code Online (Sandbox Code Playgroud)
我对websockets相当新,所以我可能完全误解了一些东西,但我希望有人能够指出我正确的方向.提前致谢!
| 归档时间: |
|
| 查看次数: |
926 次 |
| 最近记录: |