title: Spring websocket timeout settings
body: <p>I'm using the Spring websocket support. My question is how to set the websocket connection timeout. Now the connection is closed automatically after several minutes. I want the connection never to be closed.</p>
  
  <p>Here is my websocket handler:</p>
  
  <pre><code>public class MyHandler implements WebSocketHandler {
      private Logger logger = LoggerFactory.getLogger(this.getClass());
      class MyTimerTask extends TimerTask {
          private WebSocketSession session;
          public MyTimerTask(WebSocketSession session) {
              this.session = session;
          }
  
          @Override
          public void run() {
              try {
                  String msg = ((int)(Math.random()*50)) + "";
                  this.session.sendMessage(new TextMessage(msg.toString()));
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
  
      @Autowired
      private UserDao userDao;
  
      @Autowired
      private JdbcDaoImpl jdbcDaoImpl;
      private Timer timer;
  
      @Override
      public void afterConnectionEstablished(WebSocketSession session)
              throws Exception {
          System.out.println("websocket????");
          timer = new Timer();
          timer.schedule(new MyTimerTask(session), 0, 1000);
          logger.info("logger connection");
      }
  
      @Override
      public void handleMessage(WebSocketSession session,
              WebSocketMessage&lt;?&gt; message) throws Exception { }
  
      @Override
      public void handleTransportError(WebSocketSession session,
              Throwable exception) throws Exception { }
  
      @Override
      public void afterConnectionClosed(WebSocketSession session,
              CloseStatus closeStatus) throws Exception {
          System.out.println("websocket????");
          timer.cancel();
      }
  
      @Override
      public boolean supportsPartialMessages() {
          return false;
      }   
  }
  </code></pre>
  
  <p>my websocket config:</p>
  
  <pre><code>&lt;websocket:handlers&gt;
      &lt;websocket:mapping path="/myHandler" handler="myHandler"/&gt;
  &lt;/websocket:handlers&gt;
  
  &lt;bean id="myHandler" class="com.sdp.websocket.MyHandler"/&gt;
  </code></pre>
  
  <p>and javascript client:</p>
  
  <pre><code>var webserver = 'ws://localhost:8080/authtest/myHandler';
  var websocket = new WebSocket(webserver);
  websocket.onopen = function (evt) { onOpen(evt) }; 
  websocket.onclose = function (evt) { onClose(evt) }; 
  websocket.onmessage = function (evt) { onMessage(evt) }; 
  websocket.onerror = function (evt) { onError(evt) }; 
  
  function onOpen(evt) { 
      console.log("Connected to WebSocket server."); 
  } 
  
  function onClose(evt) { 
      console.log("Disconnected"); 
  } 
  
  function onMessage(evt) { 
      console.log('Retrieved data from server: ' + evt.data); 
  } 
  
  function onError(evt) { 
      console.log('Error occured: ' + evt.data); 
  }
  debugger;
  function sendMsg(){
      websocket.send("{msg:'hello'}");
  }
  </code></pre>