Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How the client handles reconnection #1404

Open
wzgl998877 opened this issue Mar 12, 2024 · 0 comments
Open

How the client handles reconnection #1404

wzgl998877 opened this issue Mar 12, 2024 · 0 comments

Comments

@wzgl998877
Copy link

My code is as follows
`@Slf4j
public class DianPingWebSocketClient extends WebSocketClient {
@Autowired
private IDianPingMessageHandle dianPingMessageHandle;

public DianPingWebSocketClient(URI serverUri) {
    super(serverUri);
}

@Override
public void onOpen(ServerHandshake serverHandshake) {
    log.info("成功连接到大众点评websocket");
}

@SneakyThrows
@Override
public void onMessage(String message) {
    log.info("接收到大众点评消息:{}", message);
    ServerMessage serverMessage = JsonUtils.toBean(message, ServerMessage.class);
    ClientMessage clientMessage = new ClientMessage(serverMessage.getMsg_id(), serverMessage.getType(), "ack");
    dianPingMessageHandle.handleMessage(serverMessage);
    send(JsonUtils.toJson(clientMessage));
}

@Override
public void onClose(int code, String reason, boolean remote) {
    log.error("大众点评websocket断开连接,原因:{}", code);
    reconnect();
}

@Override
public void onError(Exception ex) {
    log.error("大众点评websocket连接异常:", ex);
}

}`
I'm thinking now, as a client, how should I handle reconnection?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant