每5分钟获得一次websocket错误-Broken Pipe

时间:2016-01-13 18:05:50

标签: java websocket broken-pipe

我每2秒从python脚本向websocket服务器发布数据,UI正在尝试从websocket中读取数据。每隔5分钟,websocket就会出现此错误

  

ERR java.lang.RuntimeException:java.io.IOException:   java.util.concurrent.ExecutionException:java.io.IOException:Broken   管

     

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)

     

*******************备用错误*************

     

2016-01-13T12:36:58.21-0600 [App / 0] ERR   java.lang.RuntimeException:java.lang.IllegalStateException:The   远程端点处于状态[TEXT_FU LL_WRITING],这是无效的   被调用方法的状态

     

2016-01-13T12:36:58.21-0600 [App / 0] ERR at   com.tcs.predix.beta.time.series.ingestion.websocket.WebSocketClient.postToWebSocketServer(WebSoc

下面给出了破解的代码。我做错了什么:

 @Component
public class WebSocketClient
{
     private static Logger log = Logger.getLogger(WebSocketClient.class);
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();

    @Autowired
    WebSocketConfig endPointConfig;

    @Autowired
    WebsocketEndpoint websocketEndpoint;

    private Map<String,Session> sessions =  new HashMap<String,Session>();

    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;
    }

}

这是SERVER代码:

@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();
        }
    }

0 个答案:

没有答案