1

I have two WebSocket servers that can communicate wonderfully with a client. They are on two separate machines, implemented in Java and running inside WildFly8 webservers. What I need them to do now is communicate with each other. That means: client sends message to server 1, server 1 sends message to server 2, receives the reply and sends it back to client.

The servers run on different apps in OpenShift and I need them to use websockets. Or some other type of communication, but I haven't managed to find anything that actually works so far (RMI or normal socket connections won't work).

What I basically tried to do is use the same code from the client within the onMessage method of the first server. Something like this:

@OnMessage
public void message(Session session, String msg){
  ...
  WebSocketContainer container = ContainerProvider.getWebSocketContainer();
  Session NewSession = container.connectToServer(Client.class, URI.create(URL));
  NewSession.getBasicRemote().sendText("Routed :" + input);
  ...
}

However, the server does not connect to the other server and I don't know why. Any suggestions?

Thank you!

Ciri
  • 371
  • 1
  • 6
  • 19

1 Answers1

0

Put connectToServer inside a try {} catch, you might get an error. Log it.

I'm struggling to do exactly the same things (2 websocket servers, Wildfly 8), and I get a permission denied error. See my post here:

https://stackoverflow.com/questions/30966757/java-server-to-server-communication-with-websockets-permission-denied

Community
  • 1
  • 1
ThompsonCodes
  • 35
  • 1
  • 9