title: Getting websocket error every 5 mins -Broken Pipe
body: <p>I am posting data from a python script every 2 sec to a websocket server and UI is trying to read that from the websocket. After every 5 mins the websocket gets down with this error</p>
  
  <hr>
  
  <blockquote>
    <p>ERR java.lang.RuntimeException: java.io.IOException:
    java.util.concurrent.ExecutionException: java.io.IOException: Broken
    pipe</p>
    
    <p>2016-01-11T09:51:08.31-0600 [App/0]      ERR    at
    com.tcs.predix.beta.time.series.ingestion.websocket.WebSocketClient.postToWebSocketServer(WebSoc
    ketClient.java:76)</p>
    
    <p>*******************Alternate Error*************</p>
    
    <p>2016-01-13T12:36:58.21-0600 [App/0]      ERR
    java.lang.RuntimeException: java.lang.IllegalStateException: The
    remote endpoint was in state [TEXT_FU LL_WRITING] which is an invalid
    state for called method</p>
    
    <p>2016-01-13T12:36:58.21-0600 [App/0]      ERR    at
    com.tcs.predix.beta.time.series.ingestion.websocket.WebSocketClient.postToWebSocketServer(WebSoc</p>
  </blockquote>
  
  <hr>
  
  <p>The code where it is breaking is given below. Am I doing something wrong:</p>
  
  <hr>
  
  <pre><code> @Component
  public class WebSocketClient
  {
       private static Logger log = Logger.getLogger(WebSocketClient.class);
      WebSocketContainer container = ContainerProvider.getWebSocketContainer();
  
      @Autowired
      WebSocketConfig endPointConfig;
  
      @Autowired
      WebsocketEndpoint websocketEndpoint;
  
      private Map&lt;String,Session&gt; sessions =  new HashMap&lt;String,Session&gt;();
  
      public Response postToWebSocketServer(String data)
      {
          final Response statusResponse = new Response();
  
          try
          {
              Session predixWSSession = sessions.get("messages");
               if (predixWSSession == null || !predixWSSession.isOpen()) {
                  log.info("Opening New Connection : "+endPointConfig.getPredixWebSocketURI());
                  URI predixWebSocketURI = new URI(endPointConfig.getPredixWebSocketURI());
                  websocketEndpoint = new WebsocketEndpoint();
                  predixWSSession = container.connectToServer(websocketEndpoint, predixWebSocketURI);
                  predixWSSession.setMaxIdleTimeout(0);
                  sessions.put("messages", predixWSSession);
               }else {
                  log.info("Reusing existing Connection");
               }
               predixWSSession.getBasicRemote().sendText(data);
  
          }
          catch(Exception ex)
          {
              ex.printStackTrace();
              throw new RuntimeException(ex);
          }
          return statusResponse;
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p>Here is the SERVER Code:</p>
  
  <pre><code>@OnMessage
      public void OnMessage(String message, Session session) throws IOException {
          // _logger.info("Message : "+message);
          try {
              if ("messages".equalsIgnoreCase(nodeId)) {
  
                  for (Session s : session.getOpenSessions()) {
                      System.out.println(s.getRequestURI().toString());
                      s.getBasicRemote().sendText(message);
                  }
  
                  //session.getBasicRemote().sendText(message);
              } else {
                  session.getBasicRemote().sendText("SUCCESS");
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  </code></pre>