如何使服务器端事件触发Websocket消息?

时间:2018-09-22 21:33:31

标签: java atmosphere

我是Atmosphere框架的新手,如何使服务器端事件触发Websocket消息?

@WebSocketHandlerService
public class MyWebsocketHandler implements WebSocketHandler {
    @Override
    public void onByteMessage(WebSocket webSocket, byte[] bytes, int i, int i1) throws IOException {
        System.out.println("onByteMessage");
    }

    @Override
    public void onTextMessage(WebSocket webSocket, String s) throws IOException {
        System.out.println("onTextMessage - " + s);

    }

    @Override
    public void onOpen(WebSocket webSocket) throws IOException {
        System.out.println("onOpen");

    }

    @Override
    public void onClose(WebSocket webSocket) {
        System.out.println("onClose");

    }

    @Override
    public void onError(WebSocket webSocket, WebSocketProcessor.WebSocketException e) {
        System.out.println("onError");

    }
}

例如,对于此代码,我希望在服务器事件发生时调用onTextMessage方法,例如数据库已更新,我想使其触发消息上的websocket,以便客户端可以接收响应

0 个答案:

没有答案