my NetServer's closeHandler do not catch it when a client is disconnected.

411 views
Skip to first unread message

anonymous

unread,
Apr 2, 2017, 5:36:59 AM4/2/17
to vert.x
I'm a beginner in Vert.x, networking, programming, and writing in English.

So, I ask for your understanding that the explanation may be inaccurate in many terms.



Anyway, I've developed a Android simple chat app using vert.x NetServer.

When the chat app exits gracefully, my NetServer's closeHandler can catch it.

However, when I intentionally disable network connection of my Android phone (by touching WIFI button, for example),

Vert.x NetServer's closeHandler don't catch it, so it thinks that my Android phone is still joining the chat room.



When I activate my Android phone's network connection (by touching WIFI button again) and send some messages to Vert.x NetServer,

then the server recognize something happens, throw some exceptions(java.io.IOException: Connection reset by peer), and close previous connections.



How can I solve it?

Let me know if some of my codes need to be revealed.

Thank you in advance.

Tim Fox

unread,
Apr 2, 2017, 6:38:22 AM4/2/17
to vert.x
TCP is a reliable protocol, and turning off your network interface (or cutting a network cable, etc) won't close the connection. That's just how TCP works. In the eyes of the server the connection is still alive but just hasn't sent any packets for a while.

To get around this you can set idle timeout on the Vert.x server and it will automatically close connections that have been inactive for a certain time, at which point the server side close handler will be called.

Tim Fox

unread,
Apr 2, 2017, 6:47:06 AM4/2/17
to vert.x
Forget to say  - if you use idle timeout, make sure you ping some data periodically from the client, otherwise the connection will be closed if there is no traffic.

sandeepsahoo2k2

unread,
Apr 2, 2017, 9:20:01 AM4/2/17
to vert.x

netSocket.closeHandler(new Handler<Void>() {

                    @Override

                    public void handle(Void aVoid) {

                        System.out.println("Socket Closed");

                    }

                });


Use this and you get the socket close event .. I am using it and it works but with this approach you need further parsing


netSocket.handler(buffer -> {

                        System.out.println(buffer.toString()); //parsing etc required

                    });


So to avoid the parsing you can use the TCPEventBridge and use EventBus consumer approach but unfortunately vertx haven't provided any close handler for socket close with this TCPEventBusBridge approach where even I am also struggling.

anonymous

unread,
Apr 2, 2017, 5:33:30 PM4/2/17
to vert.x
Thank you all. I eventually solve it. :)

2017년 4월 2일 일요일 오후 6시 36분 59초 UTC+9, anonymous 님의 말:
Reply all
Reply to author
Forward
0 new messages