So I have a Websocket Session that reads information from a server. However if I cut off the information that it's receiving completely, after about a minute or so it will stop receiving new information, and won't do anything, even when the output from the server is turned back on.
I thought that the WebSocketContainer method
setDefaultMaxSessionIdleTimeout(Long time)
would fix my issue, so I set it to
container.setDefaultMaxSessionIdleTimeout(86400000L);
which I thought would mean it will continue running up to 1 day of inactivity.
However this is not the case, it stops after just a minute of inactivity. Below is the code I'm using, maybe someone can let me know what I'm doing wrong:
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);
}
}
I'm fairly new to websockets so I may be completely misunderstanding something, but I hope someone will be able to point me in the right direction. Thanks in advance!