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

Emit or Ack timeout handling? #309

Closed
engineers-bojan opened this issue Jun 7, 2016 · 6 comments
Closed

Emit or Ack timeout handling? #309

engineers-bojan opened this issue Jun 7, 2016 · 6 comments
Milestone

Comments

@engineers-bojan
Copy link

Is there a suggested way how to implement or handle this issue?

The iOS client version has the timeout option, but there is none found on Android SDK.

Without it, we are experiencing difficulties handling use cases where network connectivity is low and sockets are emitted but there are no callbacks if the emit was successful....

@wedneyyuri
Copy link

There is no timeout for ACK on socket.io. You need to implement it if required.

See #204 and socketio/socket.io#828

@engineers-bojan
Copy link
Author

If i may suggest this feature in the following releases :)

But in the case i am implementing this how am i to battle socket emitting buffered events?

#322

Consider the following situation:
I try to emit an event but the socket disconnects at that moment. The event is buffered in the socket internal variable. After a few minutes the socket reconnects and it will emit all the buffered events. There is no way to cancel buffered events or to clear those buffers.

This is a major drawback in implementing ACK timeout, since any timers/handlers i might implement that will notify me of ack timeout are potentially invalid as the socket may reconnect and emit those events and trigger the acks afterwards....the proper way would be to timeout the acks with the event buffers themselves.


Does this make sense? The only solution for now as i see it is to fork the code and make the modifications required for my project?

@AljoSt
Copy link

AljoSt commented Jul 1, 2016

In order to accomplish timeout handling, one could just create a timestamp queue in the Socket class, add a timestamp here and check the timestamp here right?

@carlbenson
Copy link

@AljoSt did you implement this? I'm also thinking about looking into this. Wouldn't the problem with the timestamp approach be that if there is no ack ever, how could you ever check the timestamp? I think perhaps one would add some timeout here and when the timeout occurs and the sendBuffer still contains the message, it should be removed.

@AljoSt
Copy link

AljoSt commented Feb 1, 2017

@carlbenson No, unfortunately the project I used socket.io for kinda slowed down to a halt. So I didn't get to implement the workaround. As far as I remember I wanted to use two timestamp checks:
A wrapper class that that calls socket.io for emitting does it, as well as socket.io. If the time runs out, the wrapper class would call some "onTimeout" callback to let the application know about it. And socket.io would drop the message here. The timestamp is created when first emit fails here. Hope that helps, but maybe I didn't get your problem since I didn't look into this for a long time :P

darrachequesne added a commit that referenced this issue Jul 8, 2022
This feature allows to send a packet and expect an acknowledgement from
the server within the given delay.

Syntax:

```java
socket.emit("hello", "world", new AckWithTimeout(5000) {
    @OverRide
    public void onTimeout() {
        // ...
    }

    @OverRide
    public void onSuccess(Object... args) {
        // ...
    }
});
```

Related:

- #309
- #517
@darrachequesne
Copy link
Member

Here we go:

socket.emit("hello", "world", new AckWithTimeout(5000) {
    @OverRide
    public void onTimeout() {
        // ...
    }

    @OverRide
    public void onSuccess(Object... args) {
        // ...
    }
});

Added in version 2.1.0.

@darrachequesne darrachequesne added this to the 2.1.0 milestone Jul 10, 2022
cedev935 added a commit to cedev935/socket-java that referenced this issue Sep 14, 2023
This feature allows to send a packet and expect an acknowledgement from
the server within the given delay.

Syntax:

```java
socket.emit("hello", "world", new AckWithTimeout(5000) {
    @OverRide
    public void onTimeout() {
        // ...
    }

    @OverRide
    public void onSuccess(Object... args) {
        // ...
    }
});
```

Related:

- socketio/socket.io-client-java#309
- socketio/socket.io-client-java#517
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants