Tyrus客户端websocket消息处理程序

时间:2015-07-07 23:02:11

标签: java websocket tyrus

我遇到的问题是客户端在eclipse中没有以非调试模式启动。消息确实以调试模式显示。 如果其他人也遇到同样的问题,请告诉我。

    Calling method:
client = ClientManager.createClient();
           ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
           client.getProperties().put(ClientProperties.PROXY_URI, "http://192.168.1.1:80");
    session = client.connectToServer(new ClientEndpoint(), cec,  URI.create(url));

Below is the code of ClientEndpoint class:
private static class ClientEndpoint extends Endpoint {
        @Override
        public void onOpen(final Session session, EndpointConfig config) {
            System.out.println("ClientEndpoint: server session opened: "+session);

            session.addMessageHandler(new MessageHandler.Whole<String>() {
                @Override
                public void onMessage(String message) {
                    System.out.println("ClientEndpoint: received message: "+message);
                    if(lastmessage != message)
                    {
                    lastmessage = message;
                    session.getUserProperties().put("Message", lastmessage);
                    }
                    else
                    {
    enter code here

                    session.getUserProperties().put("Message", lastmessage);
                    }
                }
            });

        }

        @Override
        public void onClose(Session session, CloseReason closeReason) {
            try {
                latch.countDown();
                session.close();
                safeDisconnect(session);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }

        @Override
        public void onError(Session session, Throwable th)
        {
            try {
                session.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            th.printStackTrace();
        }
    }

有什么想法?请让我知道配置。

0 个答案:

没有答案