0

I'm trying to use websocket using openshift and wildfly 8.1.

The application works on a local wildfly server on port 8080.

But, I'm not able to connect on openshift server for the websocket using port 8000.

Curriously, if I use port forwarding (rhc port-forward), I'm able to connect on the local forwarded port.

I think there is a missconfiguration for port forwarding on openshift.

Here is my code :

import javax.websocket.EncodeException;
import javax.websocket.CloseReason;
import javax.websocket.EndpointConfig;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.OnError;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/ws/websocket")
public class WebSocketService{
    @OnOpen
    public void onOpen(Session peer, EndpointConfig config) {
        System.err.println("Open");
        peer.getAsyncRemote().sendText("Hello");
    }

    @OnClose
    public void onClose(Session peer, CloseReason reason) {
        System.err.println("Close");
    }

    @OnError
    public void onError(Session peer, Throwable throwable) {
        System.err.println("Error");
    }
}
nono
  • 1,462
  • 1
  • 13
  • 21

1 Answers1

2

WildFly port on OpenShift should be 8080, not 8000 as you mentioned.

Are you able to connect to localhost:8080 and redirected to your OpenShift instance ?

Does Chrome Developer Tools show any errors ?

Arun Gupta
  • 3,965
  • 5
  • 31
  • 39
  • With chrome websocket tool, I've tried all ports, 8080 and 8000. Using 8000 show a connected status but I didn't receive anything. With port forwarding, I'm able to connect and receive data on port 8080. Do you confirm that on OpenShift, the wildfly websocket port is 8080 and not 8000 ? – nono Sep 05 '14 at 10:08
  • WildFly application port on OpenShift is 8080. Can you print messages on onOpen, onError, onClose ? – Arun Gupta Sep 06 '14 at 15:14
  • I've created a sample application with the above code and I've tried to connect without success and nothing is in the log file. The websocket url is : ws://wildfly8-houari.rhcloud.com:8080/wildfly8/ws/websocket – nono Sep 08 '14 at 05:40
  • I've modified the onOpen to receive "Hello" on connection. So if you are able to connect, you will receive this message. For me the status is connecting, but nothing happends. – nono Sep 08 '14 at 05:52
  • I confirm that it dosen't work on Openshift but it's working locally and with port forwarding. I also confirm that the Openshift port for websocket is not 8080 but 8000. I can connect on port 8000 ! I can receive the "Hello" message on this port. – nono Sep 08 '14 at 06:38
  • Confirming that the WebSocket port on OpenShift is indeed 8000. Read all about it at: https://www.openshift.com/blogs/paas-websockets. Try a simple application (https://github.com/javaee-samples/javaee7-samples/tree/master/websocket/chat) and deploy on OpenShift, and see how that works. I tried a moderately complex app (http://vaadin-milestogo.rhcloud.com:8000/) and could simulate ~200 concurrent users all connected using WebSocket. – Arun Gupta Sep 09 '14 at 06:49