How to connect to the socket? if 1 address is not working

All code in the service

Socket socket = null; try { socket = new Socket("188.244.144.211", 49111); } catch (IOException e) { socket = new Socket("188.244.144.212", 49111); } 

It still does not work, the program on the android works and does not crash, but there is also no shortcut.

How to do so to connect to 1 ip if there is no connection then connect to 2?

It's amazing that even I can't check if the server is working with this IP right now. Debag also does not help PEOPLE HELP !!!

    1 answer 1

    Most likely it is a time-out, by default it can be very long and Exception will not appear until the gap for this reason. It is better to try to connect to the socket in another way, clearly indicating a timeout, for example, here it is 10 seconds:

      new Thread(new Runnable() { @Override public void run() { Socket socket = new Socket(); SocketAddress sockaddr = null; try { sockaddr = new InetSocketAddress("188.244.144.211", 49111); socket = new Socket(); socket.connect(sockaddr, 10000); } catch (IOException e) { e.printStackTrace(); try { sockaddr = new InetSocketAddress("188.244.144.212", 49111); socket = new Socket(); socket.connect(sockaddr, 10000); } catch (IOException e1) { e1.printStackTrace(); } } finally { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } }).start();