Matthias247 / jawampa

Web Application Messaging Protocol (WAMP v2) support for Java
Apache License 2.0
148 stars 56 forks source link

State not changed to disconnected when connection is lost #100

Open borjaj opened 7 years ago

borjaj commented 7 years ago

Hi, I need to execute a particular method when the connection to the server is lost. I have subscribed to status events, they work ok from disconected-connecting-connected state but nothing happens when I shut down internet connection..

client.statusChanged().subscribe(t1 -> { LOGGER.info("WAMP Session status changed to " + t1);

        if(t1 instanceof  WampClient.DisconnectedState){
            LOGGER.info("DISC");
        }

...

Thanks in advance ;)

Matthias247 commented 7 years ago

Most likely the usual issue of operating systems not reporting a TCP connection state reliably. That's e.g. what happens when you just plug a network cable while nothing is transferred: There's no FIN received, so OS thinks connection is still alive. And as no sends happen the TCP stack also does not see these are failing.

Remedies for that are either some heartbeat messages on transport layer (websocket pings would work, but are not sent by jawampa). Or polling some arbitrary method on application layer just for regular checking if the connection still works. If an error is discovered then the Disconnected event should be emitted.