Exemple #1
0
        private void DoStartAdvertising()
        {
            Task.Run(() =>
            {
                _listenerSocket = BluetoothSockets.CreateRfcommSocket();
                _listenerSocket.Bind(new BluetoothEndPoint(0, _serviceUuid));

                try
                {
                    _listenerSocket.Listen(1);

                    // TODO: Publish SDP record

                    while (_listenerSocket != null)
                    {
                        var socket = _listenerSocket.Accept();
                        ConnectionReceived?.Invoke(this, new RfcommConnectionReceivedEventArgs(new System.Net.Sockets.NetworkStream(socket)));
                    }
                }
                catch
                {
                    //TODO: only trap thread cancellation here
                }
            });
        }
Exemple #2
0
 private Task <Stream> OpenStreamAsyncImpl()
 {
     return(Task.Run <Stream>(() =>
     {
         var socket = BluetoothSockets.CreateRfcommSocket();
         socket.Connect(new BluetoothEndPoint(this));
         return new NetworkStream(socket);
     }));
 }
Exemple #3
0
        public Stream OpenStream()
        {
            var socket = BluetoothSockets.CreateRfcommSocket();

            socket.Connect(new BluetoothEndPoint(this));
#if UNITY
            return(new InTheHand.Networking.Sockets.NetworkStream(socket));
#else
            return(new NetworkStream(socket));
#endif
        }