示例#1
0
        private void OnSocketConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            Windows.Foundation.IAsyncAction task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                //rootPage.NotifyUser("Connecting to remote side on L4 layer...", NotifyType.StatusMessage);
                StreamSocket serverSocket = args.Socket;

                SocketReaderWriter socketRW = new SocketReaderWriter(serverSocket, this);
                // The first message sent is the name of the connection.
                string message = await socketRW.ReadMessageAsync();

                // Find the pending connection and add it to the list of active connections.
                if (_pendingConnections.TryRemove(sender, out WiFiDirectDevice wfdDevice))
                {
                    ConnectedDevices.Add(new ConnectedDevice(message, wfdDevice, socketRW));
                }

                while (message != null)
                {
                    message = await socketRW.ReadMessageAsync();
                }
            });
 public ConnectedDevice(string displayName, WiFiDirectDevice wfdDevice, SocketReaderWriter socketRW)
 {
     DisplayName = displayName;
     WfdDevice   = wfdDevice;
     SocketRW    = socketRW;
 }