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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -