diff src/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 410:e2a56e383bad

wait for monitor socket to be created
author Carl Byington <carl@five-ten-sg.com>
date Fri, 24 Oct 2014 17:41:43 -0700
parents d3c5480e8441
children 8bff0bfaec3a
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Fri Oct 24 14:35:04 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Fri Oct 24 17:41:43 2014 -0700
@@ -174,10 +174,20 @@
 
             try {
                 InetAddress serverAddr = InetAddress.getByName(LOCALHOST);
-                monitor_socket = new Socket(serverAddr, MONITORPORT);
+                int tries = 0;
+                while (tries < 5) {
+                    try {
+                        monitor_socket = new Socket(serverAddr, MONITORPORT);
+                    }
+                    catch (IOException e) {
+                        Log.e(TAG, "exception connecting to monitor socket", e);
+                        tries = tries + 1;
+                        Thread.sleep(1000);
+                    }
+                }
+                Log.i(TAG, "connected to monitor socket, send init " + init);
                 monitor_in     = monitor_socket.getInputStream();
                 monitor_out    = monitor_socket.getOutputStream();
-                Log.i(TAG, "connected to monitor socket, send init " + init);
                 monitor_reader = new MyReader(monitor_in);
                 monitor_reader.start();
                 String x = "  " + init;