rest - Check if RESTful server is available on Android -
i'm developping android rest-api oriented application.
i need create method check whether server available or not. problem if use url.openstream() method, there's no way determine whether request successful or not.
is there way without need operate of performing full httpurlconnection , read return code?
you can use tcp sockets
socketaddress socketaddress = new inetsocketaddress(address, port); try { int timeout = 2000; socket.connect(socketaddress, timeout); } catch (ioexception e) { return false; } { if (socket.isconnected()) { try { socket.close(); } catch (ioexception e) { e.printstacktrace(); } } }
Comments
Post a Comment