Seed also integrates the Java API for WebSocket (JSR 356), allowing server and client endpoints to be injected. WebSocket support requires Java 7 and a compatible server to work.

Server endpoints

No specific configuration is required for server endpoint. Just declare a standard JSR 356 endpoint:

@ServerEndpoint(value = "/chat")
public class ChatEndpoint {

    private Logger logger;

    EchoService echoService;

    public void onOpen(Session session) {
        logger.info("Connected ... " + session.getId());

    public void message(String message, 
                        Session client) throws IOException, EncodeException {
        for (Session peer : client.getOpenSessions()) {

    public void onClose(Session session, CloseReason closeReason) {
        logger.info(String.format("Session %s close because of %s", 
            session.getId(), closeReason));

    public void onError(Session session, Throwable t) {
        logger.error(t.getMessage, t);


In this example, the endpoint receives a message and then broadcast it to all clients.

Client endpoints

Unlike server endpoints, client endpoints have to explicitly specify a SeedClientEndpointConfigurator in order to be managed by Seed.

@ClientEndpoint(configurator = SeedClientEndpointConfigurator.class)
public class ChatClientEndpoint1 {
    public static final String TEXT = "Client1 joins";
    public static CountDownLatch latch;
    public static String response;

    public void onOpen(Session session) {
        try {
        } catch (IOException ioe) {

    public void processMessage(String message) {
        response = message;

On this page