Skip to content

Send message to all connected web socket clients #645

@mer23

Description

@mer23

I'm using Jooby's MVC routes for an API. I have also set up a websocket, to which a few clients connect. What I'm trying to do is send a message to all connected websocket clients whenever a specific http request is received in the server. This is how my route method looks like:

    @Path("/player")
    @Produces("application/json")
    public class PlayerRoute {
        @POST
        public Result newPlayer(Request req, @Body Player player) {
            //this is what I'm trying to achieve..
            allWebsocketSessions.foreach(session ->
                    session.send("a new player has been created")
            );
            return Results.ok();
        }
}

I've read jooby's documentation but can't figure out how to do it.

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions