public async Task ConnectAsync(ushort maxConnectAttempts = 1) { System.Diagnostics.Debug.WriteLine("BluetoothDeviceTransport::Connect() called"); var deviceService = await RfcommDeviceService.FromIdAsync(_deviceInfo.Device.Id); if (deviceService == null) { throw new Exception("Failed to create RfcommDeviceService with id: " + _deviceInfo.Id.ToString()); } var streamSocket = new StreamSocket(); await streamSocket.ConnectAsync(deviceService.ConnectionHostName, deviceService.ConnectionServiceName); CargoStream = new BluetoothStreamWrapper(streamSocket); // we could have used streamSocket.Input/OutputStream.AsStreamForRead/Write but they don't support timeouts // and it turns out those are super important if you don't want to lock up constantly on random calls (like // trying to get the background when there isn't one :( ). CargoReader = new CargoStreamReader(CargoStream, BufferServer.GetPoolInternal(8152)); CargoWriter = new CargoStreamWriter(CargoStream, BufferServer.GetPoolInternal(8152)); }