我正在尝试使用 openshift 和 wildfly 8.1 来使用 websocket。
该应用程序在端口 8080 上的本地 Wildfly 服务器上运行。
但是,我无法使用端口 8000 连接到 websocket 的 openshift 服务器。
奇怪的是,如果我使用端口转发(rhc port-forward),我可以连接到本地转发端口。
我认为 openshift 上的端口转发配置错误。
这是我的代码:
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");
}
}