public static async Task <SmartGlassClient> ConnectAsync(
            string addressOrHostname, string xboxLiveUserHash, string xboxLiveAuthorization)
        {
            var device = await Device.PingAsync(addressOrHostname);

            var cryptoContext = new CryptoContext(device.Certificate);

            using (var transport = new MessageTransport(device.Address.ToString(), cryptoContext))
            {
                var deviceId       = Guid.NewGuid();
                var sequenceNumber = 0u;

                var initVector = CryptoContext.GenerateRandomInitVector();

                Func <Task> connectFunc = async() =>
                {
                    var requestMessage = new ConnectRequestMessage();

                    requestMessage.InitVector = initVector;

                    requestMessage.DeviceId = deviceId;

                    requestMessage.UserHash      = xboxLiveUserHash;
                    requestMessage.Authorization = xboxLiveAuthorization;

                    requestMessage.SequenceNumber = sequenceNumber;
                    requestMessage.SequenceBegin  = sequenceNumber + 1;
                    requestMessage.SequenceEnd    = sequenceNumber + 1;

                    sequenceNumber += 2;

                    await transport.SendAsync(requestMessage);
                };

                var response = await TaskExtensions.WithRetries(() =>
                                                                transport.WaitForMessageAsync <ConnectResponseMessage>(
                                                                    connectTimeout,
                                                                    () => connectFunc().Wait()),
                                                                connectRetries);

                return(new SmartGlassClient(
                           device,
                           response,
                           cryptoContext));
            }
        }