本节描述声明式WebSocket编程,可以与后一篇编程式WebSocket作对比学习: 首先上服务端: @ServerEndpoint("/chat") public class DeclarativeServer { @OnOpen public void onOpen(Session session) { System.out.println("Somebody is coming!"); }
接上篇,这篇我们采用编程式WebSocket实现上篇的例子: 服务端Endpoint,不再使用ServerEndpoint注解: public class ProgramerServer extends Endpoint { @Override public void onOpen(Session session, EndpointConfig edc) { System.out.println("Somebody is coming!");