- // Reset the ConnectThread because we're done
- AltosBluetooth.this.notify();
- connect_thread = null;
- if (D) Log.i(TAG, "Completed connect");
+ synchronized (AltosBluetooth.this) {
+ if (!closed())
+ local_socket = socket;
+ }
+
+ if (local_socket != null) {
+ try {
+ // Make a connection to the BluetoothSocket
+ // This is a blocking call and will only return on a
+ // successful connection or an exception
+ local_socket.connect();
+ } catch (Exception e) {
+ AltosDebug.debug("Connect exception %s", e.toString());
+ try {
+ local_socket.close();
+ } catch (Exception ce) {
+ AltosDebug.debug("Close exception %s", ce.toString());
+ }
+ local_socket = null;