0
我正在使用Jooby的MVC路由API。我還建立了一個websocket,有幾個客戶端連接到這個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的文檔,但無法弄清楚如何去做。
在此先感謝。
您可以訂閱所有用戶的主題,將消息發送到這個話題。 – user1516873