在 @ServerEndpoint("/wsServer") 端点的onmessage方法 上为/wsDashboard创建 Java Web Socket 客户端,并将其保存在用户属性中。当您收到消息时,只需将消息转发到 /wsServer Web 套接字。
@ServerEndpoint("/wsServer")
public class MyWSServerEndPoint{
@OnOpen
public void open( Session session) {
// Open java client websocket connection to /wsDashboard and keep the object in
session.getUserProperties().put("wsDashboard ", websocket);
}
@OnMessage
public void onMessage(String message,Session session){
//forwarding the message
session.getUserProperties().get("wsDashboard ").getRemote().send(message);
}
@OnClose
public void onClose(Session session){
session.getUserProperties().get("wsDashboard ").close();
}
}
在此处创建客户端端点是很好的示例
http://www.hascode.com/2014/11/creating-different-websocket-chat-clients-in-java/