turt2live

Untitled

Jun 16th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.net.Socket;
  4.  
  5. public class Alarm {
  6.  
  7.     public static void main(String[] args){
  8.         int reconnect = 0;
  9.         while (reconnect < 4){
  10.             try{
  11.                 Socket socket = new Socket("68.148.21.30", 5024);
  12.                 BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  13.                 String line;
  14.                 while (socket.isConnected()){
  15.                     while ((line = in.readLine()) != null){
  16.                         System.out.println(line);
  17.                     }
  18.                 }
  19.                 in.close();
  20.                 socket.close();
  21.             }catch(Exception e){
  22.                 if(e.getMessage().toLowerCase().contains("closed")){
  23.                     System.out.println("Lost connection");
  24.                 }
  25.             }
  26.             reconnect++;
  27.             try{
  28.                 Thread.sleep(1000);
  29.             }catch(InterruptedException e){}
  30.         }
  31.         System.out.println("Lost connection. Exiting...");
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment