java - WebSocket Session closes after not receiving input for some time -
so have websocket session reads information server. if cut off information it's receiving completely, after minute or stop receiving new information, , won't anything, when output server turned on.
i thought websocketcontainer method
setdefaultmaxsessionidletimeout(long time)
would fix issue, set
container.setdefaultmaxsessionidletimeout(86400000l);
which thought mean continue running 1 day of inactivity.
however not case, stops after minute of inactivity. below code i'm using, maybe can let me know 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 connect - deploymentexception:", de); } catch (ioexception ioe) { log.error("ioexception:", ioe); } if (this.session == null) { throw new runtimeexception("unable connect endpoint."); } log.info("max idle timeout: " + session.getmaxidletimeout()); log.info("connected."); log.info("type \"exit\" cancel."); log.info("...waiting data..."); bufferedreader br = new bufferedreader(new inputstreamreader(system.in)); string input; try { { 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 websockets may misunderstanding something, hope able point me in right direction. in advance!
can try setmaxidletimeout(0) on session
?
according setdefaultmaxsessionidletimeout
docs:
the value may overridden on per session basis using session.setmaxidletimeout(long)
Comments
Post a Comment