java - Android connecting server, how do I stop the socket after a certain amount of time? -
i'm developing personal android application used @ home own functionality.
i trying make if server @ home either down or non-functional, disconnect after 3 seconds.
here's code:
socket socket = new socket("10.0.2.2", 26753); socket.setsotimeout(3000); printwriter out = new printwriter(socket.getoutputstream(), true); out.println("y" + e.gettext().tostring()); out.println("u" + a.gettext().tostring()); out.println("eof"); socket.close();
ignore eof @ end. there server knows when close socket
so i've put setsotimeout 3000 (3 seconds), android application doesn't respond. can put in thread, how it?
you may want try using connect timeout:
socket socket = new socket(); socket.setsotimeout(3000); socket.connect(new inetsocketaddress("10.0.2.2", 26753), 3000);
Comments
Post a Comment