So, I have a Websocket session that reads information from the server. However, if I turn off the information that he receives completely, after about a minute he will stop receiving new information and will do nothing, even if the output from the server is back on.
I thought the WebSocketContainer method
setDefaultMaxSessionIdleTimeout(Long time)
fix my problem so i set it to
container.setDefaultMaxSessionIdleTimeout(86400000L);
which, I thought, would mean that he would continue to work until 1 day of inactivity.
However, this is not so; it ceases after a minute of inaction. Below is the code I'm using, maybe someone can tell me 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 new to websockets, so I might underestimate something completely, but hope someone can point me in the right direction. Thanks in advance!
source share