Java 向所有连接的web套接字客户端发送消息

Java 向所有连接的web套接字客户端发送消息,java,websocket,Java,Websocket,我正在将的MVC路由用于API。我还建立了一个websocket,有几个客户端连接到它。我试图做的是,每当服务器中接收到特定的http请求时,向所有连接的websocket客户端发送一条消息。以下是我的路由方法的外观: @Path("/player") @Produces("application/json") public class PlayerRoute { @POST public Result newPlayer(Request req, @Body Player p

我正在将的MVC路由用于API。我还建立了一个websocket,有几个客户端连接到它。我试图做的是,每当服务器中接收到特定的http请求时,向所有连接的websocket客户端发送一条消息。以下是我的路由方法的外观:

@Path("/player")
@Produces("application/json")
public class PlayerRoute {

    @POST
    public Result newPlayer(Request req, @Body Player player) {
        //do some process here

        //this is what I'm trying to achieve..
        allWebsocketSessions.foreach(session ->
                session.send("a new player has been created")
        );

        return Results.ok();
    }
}
我读过jooby的文档,但不知道怎么做


提前感谢。

对于“会话”,您似乎只能调用“set”和“get”方法。方法“send”您可以调用“response”。

您可以向所有用户订阅该主题并向该主题发送消息。