我使用Jooby的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的文档,但无法弄清楚如何操作。
提前致谢。
答案 0 :(得分:0)
似乎“会话你可以打电话”设置“和”获取“方法。方法”发送“你可以打电话给”回复“。