Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.Socket;
- public class Alarm {
- public static void main(String[] args){
- int reconnect = 0;
- while (reconnect < 4){
- try{
- Socket socket = new Socket("68.148.21.30", 5024);
- BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- String line;
- while (socket.isConnected()){
- while ((line = in.readLine()) != null){
- System.out.println(line);
- }
- }
- in.close();
- socket.close();
- }catch(Exception e){
- if(e.getMessage().toLowerCase().contains("closed")){
- System.out.println("Lost connection");
- }
- }
- reconnect++;
- try{
- Thread.sleep(1000);
- }catch(InterruptedException e){}
- }
- System.out.println("Lost connection. Exiting...");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment