java - Retrying Android Socket connect on timeout -


i'm using socket connect server. i'm having variable time-outs depending on options i'm executing. want able retry "connect" method @ least 3 times before informing client connection couldn't opened.

i've try wrapping "connect" method in try/catch , recalling "connect" when exception catch "sockettimeoutexception" hasn't worked. know answer involves putting whole process inside for/while loop, can't seem figure out how.

any help?

something this, maybe:

private void dosomething() {      socket socket = null;      (int = 0; < 3; i++) {          try {              socket = connecttoserver();             break;          } catch (ioexception e) {              // log exception,             // show message user,             // etc.         }     }      if (socket != null) {         // ok     } else {         // not connect server.     } }  private socket connecttoserver() throws ioexception {      // returns valid socket.     // throws exception in case of problems. } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -