Advertisement
Sunny_Capt

none

Apr 21st, 2019
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. while(true){
  2.     try (SocketChannel channel = SocketChannel.open()) {
  3.         for(;;){
  4.             //тут отправляешь и получаешь данные     
  5.         }
  6.     }catch (IOException e) {
  7.         if (attNum < 8) {
  8.             System.out.printf("No server connection. Trying to connect: committed %d/8 attempts.\n", attNum);
  9.             attNum++;
  10.                 try {
  11.                     System.out.println("Connecting...");
  12.                     Thread.sleep(2000);
  13.                 } catch (InterruptedException ex) {}
  14.         } else {
  15.             System.out.println("No server connection. The available number of attempts has been exhausted.");
  16.             //завершаешь работу клиента
  17.         }
  18.    }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement