public async Task <bool> WaitForConnectionAsync(TimeSpan timeOut) { bool connected = false; this.connectionMadeTask = new TaskCompletionSource <bool>(); if (this.advertise) { this.advertiser = new BluetoothLEStreamSocketAdvertiser(); this.advertiser.ConnectionReceived += OnRemotePipeConnected; await this.advertiser.StartAsync(); } else { this.watcher = new BluetoothLEStreamSocketWatcher( IPAddressExtensions.GetForLocalInternetProfile()); this.watcher.StreamSocketDiscovered += OnRemotePipeDiscovered; this.watcher.Start(); } var completed = await Task.WhenAny( this.connectionMadeTask.Task, Task.Delay(timeOut)); connected = completed == this.connectionMadeTask.Task; this.StopAdvertisingWatching(); if (connected && !this.advertise) { connected = await this.ConnectToRemotePipeAsync(); } return(connected); }
async Task CreateForLocalInternetProfileAsync() { this.SocketListener = new StreamSocketListener(); this.ownsListener = true; this.address = IPAddressExtensions.GetForLocalInternetProfile(); await this.SocketListener.BindEndpointAsync( new HostName(this.address.ToString()), string.Empty); }
async Task CreateForLocalInternetProfileAsync() { this.SocketListener = new StreamSocketListener(); this.SocketListener.Control.NoDelay = true; this.SocketListener.Control.QualityOfService = SocketQualityOfService.LowLatency; this.ownsListener = true; this.address = IPAddressExtensions.GetForLocalInternetProfile(); await this.SocketListener.BindEndpointAsync( new HostName(this.address.ToString()), string.Empty); }