Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*UPDATED: 11/2015*/
- public static boolean isOnline(String ip, int port){
- Socket socket = null;
- try {
- socket = new Socket(InetAddress.getByName(ip),port);
- socket.setSoTimeout(10000);//Temps maximum avant une réponse pour dire qu'il est en ligne (ICi 10 secondes)
- }catch (UnknownHostException e) {
- return false;
- }catch (IOException e) {
- return false;
- }finally {
- if(socket == null)return false;
- try {
- socket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return socket.isConnected();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment