Code example for BluetoothSocket

Methods: close, connect, getInputStream, getOutputStream

1
		// if the socket was used before, we have to close it before trying to reconnect 
		// otherwise _scoket.connect() throws exception java.io.IOException: 
		// Device or resource busy 
		if (_socket != null) {
			try { 
				_socket.close();
			} catch (IOException ex) {
				Log.d(TAG, "socket close exeception" + ex);
			} 
		} 
 
		try { 
			_socket = _bluetoothTarget.createRfcommSocketToServiceRecord(uuid);
		} catch (IOException ex) {
			Log.d(TAG, "createRf returned exception " + ex);
			return false; 
		} 
 
		// if we try to connect multiple times very fast 
		// _socket.connect still throws the exception: java.io.IOException: 
		// Service discovery failed