【问题标题】:how to create standalone tyrus client for websockets inside the wildfly server to communicate between two wildfly instances如何为wildfly服务器内的websockets创建独立的tyrus客户端以在两个wildfly实例之间进行通信
【发布时间】:2015-03-12 15:52:53
【问题描述】:
  1. 尝试在两个不同的 wildfly 实例上的两个单独的可部署战争之间建立 websocket 连接。
  2. 使用 tyrus-standalone-client 建立 websocket 连接到另一场战争。

  3. 下面是用来建立web-socket连接的sn-p

问题:是否有可能使 websocket 连接到另一个可部署的战争? 我运行时找不到任何异常,甚至没有 101-404 错误(握手错误)。

    AuthConfig authConfig = AuthConfig.Builder.create().disableProvidedDigestAuth().build();
    Credentials credentials = new Credentials("root", "xyz");
    ClientManager client = ClientManager.createClient();
    client.getProperties().put(ClientProperties.AUTH_CONFIG, authConfig);
    client.getProperties().put(ClientProperties.CREDENTIALS, credentials);


    try (Session session = client.connectToServer(GovernorNodeWebSocketClient.class, new URI("ws://10.203.67.168:8080/xyz"))) {

        session.getBasicRemote().sendObject("xyz");
        System.out.println("4sendMessageToRemoteGovernor :: sent the message from device services to the remote governor"+responseObject.getJson());
    }
    catch (Exception e) {

        e.printStackTrace();
    }

【问题讨论】:

  • 是的……很有可能。
  • 是的,谢谢,它可能对我有用。

标签: java websocket glassfish wildfly-8


【解决方案1】:

是的,当我在 sn-ps 下使用时,删除凭据部分和 ClientManager.createClient();

因此,通过在 Wildfly 实例上添加 tyrus 依赖项,我们可以在它们之间建立 websocket 连接

try  {
        System.out.println("sendMessageToRemoteGovernor :: "+message.getJson());
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        session = container.connectToServer(XYZ.class, new URI("ws://localhost:8080/xyz/xyz"));
        session.getBasicRemote().sendObject(message);
    }
    catch (Exception e) {
        e.printStackTrace();
    }

【讨论】:

    猜你喜欢
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多