Inheritance: IPeerInformation
Exemple #1
0
 public PeerAppInfo(PeerInformation peerInformation)
 {
     this.PeerInfo = peerInformation;
     this.DisplayName = this.PeerInfo.DisplayName;
     //this.HostName = this.PeerInfo.HostName.DisplayName;
     //this.ServiceName = this.PeerInfo.ServiceName;
 }
 internal PairedDeviceInfo(PeerInformation peerInformation)
 {
     this.PeerInfo = peerInformation;
     this.DisplayName = this.PeerInfo.DisplayName;
     this.HostName = this.PeerInfo.HostName.DisplayName;
     this.ServiceName = this.PeerInfo.ServiceName;
 }
        private void ConnectToBrain()
        {
            try
            {
                if (!Mindwave.Current.IsConnected)
                {
                    PairedDeviceInfo pdi = Discovered_BT_List.SelectedItem as PairedDeviceInfo;
                    Windows.Networking.Proximity.PeerInformation peer = pdi.PeerInfo;

                    Mindwave.Current.Start(peer);

                    isBrainConnected = true;

                    //Mindwave.Current.allowBlinkSec = 2;
                    //Mindwave.Current.allowBlinkInterval = 2;
                    Mindwave.Current.CurrentValueChanged += Current_CurrentValueChanged;
                    Mindwave.Current.StateChanged        += Current_StateChanged;
                    //Mindwave.Current.Blinking += Current_Blinking;
                    BTDeviceCon_t.Text = Mindwave.Current.PeerInformation.DisplayName + ":" + Mindwave.Current.PeerInformation.ServiceName + ":" + Mindwave.Current.IsConnected.ToString();
                }
                else
                {
                    MessageBox.Show("No Mindwave is find!!!");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("MindWave Connection Error: " + err.Message + "\r\n" + Mindwave.Current.Err_S);

                Mindwave.Current.Dispose();
            }
        }
 public ConnectedSphero(PeerInformation peerInformation, StreamSocket spheroSocket)
     : base(peerInformation)
 {
     _spheroSocketWrapper = new StreamSocketWrapper(spheroSocket);
     _runner = new AwaitingConnectedSpheroRunner(_spheroSocketWrapper);
     _runner.Disconnected += (sender, args) => RaiseDisconnected();
     _runner.Start();
 }
 private async void _peerWatcher_Updated(PeerWatcher sender, PeerInformation args)
 {
     await this.textboxDebug.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
     () =>
     {
         this.textboxDebug.Text += "Updated\n";
     });
 }
 private void AskUserToAcceptPeerRequest(PeerInformation peer)
 {
     var result = MessageBox.Show(string.Format("Mit Peer {0} verbinden?", peer.DisplayName),
                                  "BLUETOOTH KOMMUNIKATION", MessageBoxButton.OKCancel);
     if (result == MessageBoxResult.OK)
     {
         ReceiveImage(peer);
     }
 }
 /// <inheritdoc />
 protected override void Dispose(bool disposing)
 {
     if (m_disposeService && m_deviceService != null)
     {
         m_deviceService.Dispose();
     }
     m_deviceService = null;
     m_devicePeer    = null;
     base.Dispose(disposing);
 }
Exemple #8
0
 /// <summary>
 /// 连接并发送信息给对方
 /// </summary>
 /// <param name="peerInformation"></param>
 private async void ConnectToPeer(PeerInformation peer)
 {
     dataReader = new DataReader(socket.InputStream);
     dataWriter = new DataWriter(socket.OutputStream);
     string message = "测试消息";
     uint strLength = dataWriter.MeasureString(message);
     dataWriter.WriteUInt32(strLength);
     dataWriter.WriteString(message);
     uint numBytesWritten = await dataWriter.StoreAsync();
 }
        private bool ShouldConnect(PeerInformation peerInformation)
        {
            return true;
            MessageBoxResult result = MessageBoxResult.None;
            this.Dispatcher.BeginInvoke(() =>
                {
                     result = MessageBox.Show("Do you want to connect with this peer?", "Incoming Peer Request", MessageBoxButton.OKCancel);
                });

            return (result == MessageBoxResult.OK);
        }
Exemple #10
0
        /// <summary>
        /// Creates the protocol - encapsulates the socket creation
        /// </summary>
        /// <param name="peer">The peer.</param>
        /// <returns>A protocol object</returns>
        public static async Task<Protocol> CreateProtocolAsync(PeerInformation peer)
        {
#if WINDOWS_PHONE
            // {00001101-0000-1000-8000-00805f9b34fb} specifies we want a Serial Port - see http://developer.nokia.com/Community/Wiki/Bluetooth_Services_for_Windows_Phone
            StreamSocket socket = new StreamSocket();
            await socket.ConnectAsync(peer.HostName, new Guid(0x00001101, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB).ToString("B"));
#elif NETFX_CORE
            StreamSocket socket = await PeerFinder.ConnectAsync(peer);
#endif
            return new Protocol(socket);
        }
Exemple #11
0
        /// <summary>
        /// Creates the protocol - encapsulates the socket creation
        /// </summary>
        /// <param name="peer">The peer.</param>
        /// <returns>A protocol object</returns>
        public static async Task<Protocol> CreateProtocolAsync(PeerInformation peer)
        {
#if WINDOWS_PHONE || WINDOWS_PHONE_APP
            // {00001101-0000-1000-8000-00805f9b34fb} specifies we want a Serial Port - see http://developer.nokia.com/Community/Wiki/Bluetooth_Services_for_Windows_Phone
            // {00000000-deca-fade-deca-deafdecacaff} Fix ServiceID for WP8.1 Update 2
            StreamSocket socket = new StreamSocket();
            await socket.ConnectAsync(peer.HostName, Guid.Parse("00000000-deca-fade-deca-deafdecacaff").ToString("B"));
            return new Protocol(socket);
#endif

            throw new NotImplementedException();
        }
        private async void Connect(PeerInformation peerInformation)
        {
            try
            {
                socket = await PeerFinder.ConnectAsync(peerInformation);
                PeerFinder.Stop();
                //同Socket TCP的编程方式来进行发送消息

            }
            catch (Exception eer)
            {
                MessageBox.Show(eer.Message);
            }
        }
        async private void ConnectToPeer(Windows.Networking.Proximity.PeerInformation peerInfo)
        {
            //WriteMessageText("Peer found. Connecting to " + peerInfo.DisplayName + "\n");
            try {
                Windows.Networking.Sockets.StreamSocket socket =
                    await Windows.Networking.Proximity.PeerFinder.ConnectAsync(peerInfo);

                //WriteMessageText("Connection successful. You may now send messages.\n");
                this.thingsFound.Text += "Connection successful. You may now send messages.";
                //SendMessage(socket);
            }
            catch (Exception err) {
                //WriteMessageText("Connection failed: " + err.Message + "\n");
            }
        }
        private async void ReceiveImage(PeerInformation peer)
        {
            try
            {
                Status.Text = "Verbinde mit Peer...";
                StreamSocket peerSocket = await PeerFinder.ConnectAsync(peer);
                Status.Text = "Verbunden. Empfange Daten...";

                // DataReader erzeugen, um arbeiten mit Bytes zu vereinfachen
                var reader = new DataReader(peerSocket.InputStream);

                // Anzahl der Bytes abrufen, aus denen das Bild besteht
                // Anzahl = int = 4 Bytes => 4 Bytes vom Socket laden
                await reader.LoadAsync(4);
                int imageSize = reader.ReadInt32();

                // Bytearray des Bildes laden
                await reader.LoadAsync((uint)imageSize);
                byte[] imageBytes = new byte[imageSize];
                reader.ReadBytes(imageBytes);

                // Bytearray in Stream laden und anzeigen
                using (var ms = new MemoryStream(imageBytes))
                {
                    var image = new BitmapImage();
                    image.SetSource(ms);

                    ReceivedImage.Source = image;
                }
                Status.Text = "Bild empfangen.";

                // Ressourcen freigeben
                reader.Dispose();
                peerSocket.Dispose();

                // Wieder Verbindungen akzeptieren
                PeerFinder.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fehler: " + ex.Message);
                Status.Text = "Bereit.";
            }
        }
        async void ConnectToPeer(PeerInformation peer)
        {
            try
            {
                StreamSocket socket = await PeerFinder.ConnectAsync(peer);
               
                App.Socket = socket;
                

                //imageBytes = await dataHelper.ReceiveDataAsync();

                //this.Dispatcher.BeginInvoke(() =>
                //{
                //    MessageBox.Show(string.Format("Received {0} bytes", imageBytes.Length));
                //});
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BluetoothDevice"/> class.
 /// </summary>
 /// <param name="peer">The peer information device.</param>
 public BluetoothDevice(Windows.Networking.Proximity.PeerInformation peer)
 {
     m_devicePeer = peer;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BluetoothDevice"/> class.
 /// </summary>
 /// <param name="peer">The peer information device.</param>
 public BluetoothDevice(Windows.Networking.Proximity.PeerInformation peer)
 {
     m_devicePeer = peer ?? throw new ArgumentNullException(nameof(peer));
 }
        private async Task<string[]> InitializeAndReadObdStream(PeerInformation selectedDevice)
        {
            string[] result = new string[] { string.Empty, string.Empty };

            using (StreamSocket socket = new StreamSocket())
            {
                await socket.ConnectAsync(selectedDevice.HostName, "1");

                using (var dataWriter = new DataWriter(socket.OutputStream))
                using (var dataReader = new DataReader(socket.InputStream))
                {
                    dataReader.InputStreamOptions = InputStreamOptions.None;

                    // full reset
                    //dataWriter.WriteString("AT Z");
                    //dataWriter.WriteString(Environment.NewLine);
                    //await dataWriter.StoreAsync();
                    //string reset = await this.ReadString(dataReader);

                    // default reset
                    //dataWriter.WriteString("AT D");
                    //dataWriter.WriteString(Environment.NewLine);
                    //await dataWriter.StoreAsync();
                    //string reset = await this.ReadString(dataReader);

                    // reset CRA settings
                    dataWriter.WriteString("AT AR");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader, "AT AR");

                    // 9600 baud
                    //dataWriter.WriteString("AT IB 96");
                    //dataWriter.WriteString(Environment.NewLine);
                    //await dataWriter.StoreAsync();
                    //await this.ReadAndValidateCommand(dataReader);

                    // echo off
                    dataWriter.WriteString("AT E0");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader, "AT E0");

                    // read voltage
                    dataWriter.WriteString("AT RV");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    string voltage = await this.ReadString(dataReader);

                    // set protocol to 6
                    dataWriter.WriteString("AT SP 6");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // printing of spaces off
                    dataWriter.WriteString("AT S0");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

#if FALSE
                    // line feed off 
                    dataWriter.WriteString("AT L0");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // automatically receive
                    dataWriter.WriteString("AT AR");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // CAN Receive Address (CAR CAN)
                    dataWriter.WriteString("AT CRA 1CB");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // CAN Receive Address (EV CAN)
                    dataWriter.WriteString("AT CRA 5BC");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);
#endif

                    // headers on
                    dataWriter.WriteString("AT H1");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // don't send wakeup messages
                    dataWriter.WriteString("AT SW 00");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // display data length
                    dataWriter.WriteString("AT D1");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Set header
                    dataWriter.WriteString("AT SH 79B");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Flow control set header
                    dataWriter.WriteString("AT FC SH 79B");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Flow control set data
                    dataWriter.WriteString("AT FC SD 30 00 18");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Flow control set mode (user defined responses)
                    dataWriter.WriteString("AT FC SM 1");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Group 1 (21 01) SOC = 5th line last three bytes, CAP = 6th (last) line second, third and fourth bytes.
                    dataWriter.WriteString("21 01");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    result[(int)ObdGroups.Charge] = await this.ReadString(dataReader);

                    // Group 4 (21 04) 
                    dataWriter.WriteString("21 04");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    result[(int)ObdGroups.Temperature] = await this.ReadString(dataReader);

#if PRESSURE
                    // Set header
                    dataWriter.WriteString("AT SH 745");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Flow control set header
                    dataWriter.WriteString("AT FC SH 745");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Set receive header
                    dataWriter.WriteString("AT CRA 746");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Flow control set receive header
                    dataWriter.WriteString("AT FC RA 746");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);
#endif

#if L2COUNT
                    // Set header
                    dataWriter.WriteString("AT SH 797");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Flow control set header
                    dataWriter.WriteString("AT FC SH 797");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // set protocol to 6
                    //dataWriter.WriteString("AT SP 7");
                    //dataWriter.WriteString(Environment.NewLine);
                    //await dataWriter.StoreAsync();
                    //await this.ReadAndValidateCommand(dataReader); 

                    // Set receive header
                    //dataWriter.WriteString("AT CRA 79A");
                    //dataWriter.WriteString(Environment.NewLine);
                    //await dataWriter.StoreAsync();
                    //await this.ReadAndValidateCommand(dataReader);

                    // Flow control set receive header
                    //dataWriter.WriteString("AT FC RA 79A");
                    //dataWriter.WriteString(Environment.NewLine);
                    //await dataWriter.StoreAsync();
                    //await this.ReadAndValidateCommand(dataReader);

                    dataWriter.WriteString("03 22");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    string l2Count = await this.ReadString(dataReader);

#endif

#if DEBUG
                    // Set header
                    dataWriter.WriteString("AT SH 797");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Flow control set header
                    dataWriter.WriteString("AT FC SH 797");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    await this.ReadAndValidateCommand(dataReader);

                    // Group 1 (21 01) SOC = 5th line last three bytes, CAP = 6th (last) line second, third and fourth bytes.
                    dataWriter.WriteString("03 22 11 11");
                    dataWriter.WriteString(Environment.NewLine);
                    await dataWriter.StoreAsync();
                    string ambient = await this.ReadString(dataReader);
#endif
                }
            }

            return result;
        }
 async void Connect(PeerInformation peerToConnect)
 {
     StreamSocket socket = await PeerFinder.ConnectAsync(peerToConnect);
 }
Exemple #20
0
 public PebbleBluetoothConnection( PeerInformation peerInformation )
 {
     if ( peerInformation == null ) throw new ArgumentNullException( "peerInformation" );
     _PeerInformation = peerInformation;
 }
Exemple #21
0
 private void devlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     this.selected_index = devlist.SelectedIndex;
     this.selected_target = pinfo[this.selected_index];
 }
        private async Task ConnectToPeers(PeerInformation peer)
        {            
            try
            {
                progressBar.Visibility = Visibility.Visible;

                UpdatePlayerStatus(peer, " - connecting...");                  
                StreamSocket s = await PeerFinder.ConnectAsync(peer);
                ConnectedPeer temp = new ConnectedPeer(peer.DisplayName);
                connectedPeers[temp] = new SocketReaderWriter(s, this);
                connectedPeers[temp].ReadMessage();

                UpdatePlayerStatus(peer, " - ready");
                ConnectedPlayers.Items.Add(peer.DisplayName);
                
                startGameButton.Visibility = Visibility.Visible;
            }
            catch (Exception)
            {
                sendInvitationsText.Text = "Cannot connect to " + peer.DisplayName;
            }
        
            // PeerFinder.ConnectAsync aborts PeerWatcher
            // restart PeerWatcher whether connect failed or succeeded
            StartPeerWatcher();
        }
 private void UpdatePlayerStatus(PeerInformation peer, string status)
 {
     try
     {
         for (int i = 0; i < availablePeers.Count; i++)
         {
             if (availablePeers[i].Peer.Id == peer.Id)
             {
                 if (status.Equals(" - connecting..."))
                 {
                     availablePeers[i].Status = status;
                 }
                 else if (status.Equals(" - ready"))
                 {
                     foundPeers.SelectionChanged -= PeersSelectionChanged;
                     availablePeers.RemoveAt(i);
                     foundPeers.SelectionChanged += PeersSelectionChanged;
                 }
             }
         }
     }
     catch (Exception err)
     {
         sendInvitationsText.Text = err.ToString();
     }
 }
 private void PeerWatcher_Removed(PeerWatcher sender, PeerInformation peerInfo)
 {
     var ignored = messageDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (availablePeers)
         {
             for (int i = 0; i < availablePeers.Count; i++)
             {
                 if (availablePeers[i].Peer.Id == peerInfo.Id)
                 {
                     availablePeers.RemoveAt(i);
                 }
             }
             if (availablePeers.Count == 0)
             {
                 directions.Visibility = Visibility.Collapsed;
             }
         }
     });
 }
 private void PeerWatcher_Updated(PeerWatcher sender, PeerInformation peerInfo)
 {
     var ignored = messageDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (availablePeers)
         {
             for (int i = 0; i < availablePeers.Count; i++)
             {
                 if (availablePeers[i].Peer.Id == peerInfo.Id)
                 {
                     availablePeers[i] = new AvailablePeer(peerInfo);
                 }
             }
         }
     });
 }
 internal PeerAppInfo(PeerInformation peerInformation)
 {
     this.PeerInfo = peerInformation;
     this.DisplayName = this.PeerInfo.DisplayName;
 }
    private void DoConnect(PeerInformation peerInformation)
    {
#if WINDOWS_PHONE
      if (peerInformation.HostName != null)
      {
        DoConnect(peerInformation.HostName, peerInformation.ServiceName);
        return;
      }
#endif

      PeerFinder.ConnectAsync(peerInformation).AsTask().ContinueWith(p =>
      {
        if (!p.IsFaulted)
        {
          DoConnect(p.Result);
        }
        else
        {
          Debug.WriteLine("connection fault");
          FireConnectionStatusChanged(TriggeredConnectState.Failed);
        }
      });
    }
 public void Connect(PeerInformation peerInformation)
 {
   DoConnect(peerInformation);
 }
Exemple #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BluetoothDevice"/> class.
 /// </summary>
 /// <param name="peer">The peer information device.</param>
 /// <param name="parser">Parser used for incoming messages</param>
 public BluetoothDevice(IIncomingMessageParser parser, Windows.Networking.Proximity.PeerInformation peer) : base(parser)
 {
     m_devicePeer = peer;
 }
Exemple #30
0
        private async void ConnectToDevice(PeerInformation peer)
        {
            if (_socket != null)
            {
                // Disposing the socket with close it and release all resources associated with the socket
                _socket.Dispose();
            }

            try
            {
                _socket = new StreamSocket();
                string serviceName = (String.IsNullOrWhiteSpace(peer.ServiceName)) ? tbServiceName.Text : peer.ServiceName;

                // Note: If either parameter is null or empty, the call will throw an exception
                await _socket.ConnectAsync(peer.HostName, serviceName);

                // If the connection was successful, the RemoteAddress field will be populated
               MessageBox.Show(String.Format(AppResources.Msg_ConnectedTo, _socket.Information.RemoteAddress.DisplayName));
            }
            catch (Exception ex)
            {
                // In a real app, you would want to take action dependent on the type of 
                // exception that occurred.
                MessageBox.Show(ex.Message);

                _socket.Dispose();
                _socket = null;
            }
        }
        private async Task PeerConnect(PeerInformation peer, StreamSocket socket) {
            // Store socket
            DataWriter writer = new DataWriter(socket.OutputStream);
            DataReader reader = new DataReader(socket.InputStream);

            MapPeer mapPeer = new MapPeer() {
                PeerInformation = peer,
                StreamSocket = socket,
                DataReader = reader,
                DataWriter = writer
            };
            this._peers.Add(mapPeer);

            // Listening
            await ProximityMapEnvironment.Default.Log("Listening...", true);

            // Commence send/recieve loop
            await this.PeerReceive(mapPeer);
        }
        async void ConnectToPeer(PeerInformation peer)
        {
            try
            {
                _socket = await PeerFinder.ConnectAsync(peer);

                // We can preserve battery by not advertising our presence.
                PeerFinder.Stop();

                _peerName = peer.DisplayName;
                UpdateChatBox(AppResources.Msg_ChatStarted, true);

                // Since this is a chat, messages can be incoming and outgoing. 
                // Listen for incoming messages.
                ListenForIncomingMessage();
            }
            catch (Exception ex)
            {
                // In this sample, we handle each exception by displaying it and
                // closing any outstanding connection. An exception can occur here if, for example, 
                // the connection was refused, the connection timeout etc.
                MessageBox.Show(ex.Message);
                CloseConnection(false);
            }
        }
 public PairedDeviceInfo(PeerInformation peerInformation)
 {
     id = peerInformation.HostName.ToString();
     name = peerInformation.DisplayName;
 }
Exemple #34
0
 public BluetoothDevice(PeerInformation peerInfo)
 {
     this.device = peerInfo;
 }
Exemple #35
0
        /// <summary>
        /// Connect to detected remote device.
        /// 
        /// Connecting action will be invoked when a socket connection is being created.
        /// Connected action will be invoked when a connection with another device has been established.
        /// ConnectivityProblem action will be invoked if connection to another device cannot be made.
        /// ConnectionInterrupted action will be invoked if connection to another device breaks.
        /// MessageReceived action will be invoked when a message from another device has been received.
        /// <param name="peer">Peer to connect to</param>
        /// </summary>
        public async void Connect(PeerInformation peer)
        {
            _status = ConnectionStatusValue.Connecting;

            try
            {
                if (Connecting != null)
                {
                    Connecting();
                }

                _socket = await PeerFinder.ConnectAsync(peer);

                if (_socket != null)
                {
                    PeerFinder.TriggeredConnectionStateChanged -= TriggeredConnectionStateChanged;
                    PeerFinder.ConnectionRequested -= ConnectionRequested;

                    _status = ConnectionStatusValue.Connected;

                    _writer = new DataWriter(_socket.OutputStream);
                    _writer.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
                    _writer.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian;

                    _reader = new DataReader(_socket.InputStream);
                    _reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
                    _reader.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian;

                    ListenAsync();

                    SendNameAsync(NFCTalk.DataContext.Singleton.Settings.Name);

                    if (Connected != null)
                    {
                        Connected();
                    }
                }
                else if (ConnectivityProblem != null)
                {
                    ConnectivityProblem();
                }
            }
            catch (Exception ex)
            {
                if (ConnectivityProblem != null)
                {
                    ConnectivityProblem();
                }
            }
        }
 private void PeerWatcher_Added(PeerWatcher sender, PeerInformation peerInfo)
 {
     var ignored = messageDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (availablePeers)
         {
             noPeersFound.Visibility = Visibility.Collapsed;
             availablePeers.Add(new AvailablePeer(peerInfo));
             // Don't overlap NFC text, only show this if the ListView is enabled
             if (foundPeers.IsEnabled)
             {
                 directions.Visibility = Visibility.Visible;
             }
         }
     });
 }