Vinetos

[Socket] Status du serveur [Updated]

May 25th, 2015
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. /*UPDATED: 11/2015*/
  2. public static boolean isOnline(String ip, int port){
  3. Socket socket = null;
  4. try {
  5. socket = new Socket(InetAddress.getByName(ip),port);
  6. socket.setSoTimeout(10000);//Temps maximum avant une réponse pour dire qu'il est en ligne (ICi 10 secondes)
  7.  
  8. }catch (UnknownHostException e) {
  9. return false;
  10. }catch (IOException e) {
  11. return false;
  12. }finally {
  13. if(socket == null)return false;
  14. try {
  15. socket.close();
  16. } catch (IOException e) {
  17. e.printStackTrace();
  18. }
  19. return socket.isConnected();
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment