コード例 #1
0
        public AcceptThread(BluetoothConnectionManager manager, bool secure)
        {
            BluetoothServerSocket tmp = null;

            socketType   = secure ? "Secure" : "Insecure";
            this.manager = manager;

            try
            {
                if (secure)
                {
                    tmp = manager.btAdapter.ListenUsingRfcommWithServiceRecord(BluetoothConnectionManager.NAME_SECURE, BluetoothConnectionManager.MY_UUID_SECURE);
                }
                else
                {
                    tmp = manager.btAdapter.ListenUsingInsecureRfcommWithServiceRecord(BluetoothConnectionManager.NAME_INSECURE, BluetoothConnectionManager.MY_UUID_INSECURE);
                }
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(BluetoothConnectionManager.TAG, "listen() failed", e);
            }
            serverSocket  = tmp;
            manager.state = STATE_LISTEN;
        }
コード例 #2
0
            public AcceptThread(BluetoothService service, Boolean secure)
            {
                BluetoothServerSocket tmp = null;

                _socketType   = secure ? "Secure" : "Insecure";
                this._service = service;

                try
                {
                    if (secure)
                    {
                        tmp = service._btAdapter.ListenUsingRfcommWithServiceRecord(Constants.NAME_SECURE,
                                                                                    Constants.MY_UUID_SECURE);
                    }
                    else
                    {
                        tmp = service._btAdapter.ListenUsingInsecureRfcommWithServiceRecord(Constants.NAME_INSECURE,
                                                                                            Constants.MY_UUID_INSECURE);
                    }
                }
                catch (IOException e)
                {
                    Log.Error(Constants.TAG, "listen() failed", e);
                }
                _serverSocket  = tmp;
                service._state = Constants.STATE_LISTEN;
            }
コード例 #3
0
            public AcceptThread(bool secure, SendData sd)
            {
                try
                {
                    BluetoothServerSocket temp;
                    sendData = sd;

                    if (secure)
                    {
                        temp = sendData.BluetoothAdapter.ListenUsingRfcommWithServiceRecord("Bluetooth Chat Service", sendData.uuid);
                    }
                    else
                    {
                        temp = sendData.BluetoothAdapter.ListenUsingInsecureRfcommWithServiceRecord("Insecure Bluetooth Chat Service", sendData.uuid);
                    }

                    mmServerSocket = temp;
                    sendData.state = StateEnum.Listen;
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString() + "!!!");
                    throw;
                }
            }
コード例 #4
0
 /// <summary>
 /// Creates a new listener.
 /// </summary>
 /// <param name="address">The local address to use.</param>
 /// <param name="handler">The function to call when a request is received.</param>
 public BluetoothContactRequestListener(ErebusAddress address, Func <ErebusAddress, string, bool> handler)
 {
     addr = address;
     h    = handler;
     l    = BluetoothAdapter.DefaultAdapter.ListenUsingRfcommWithServiceRecord("ErebusContactRequest", BluetoothUtils.RfcommAddContactService);
     lt   = listenProcess();
 }
コード例 #5
0
            public AcceptThread(BluetoothChatService service, bool secure)
            {
                BluetoothServerSocket tmp = null;

                socketType   = secure ? "Secure" : "Insecure";
                this.service = service;

                try
                {
                    if (secure)
                    {
                        tmp = service.btAdapter.ListenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE);
                    }
                    else
                    {
                        tmp = service.btAdapter.ListenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE);
                    }
                }
                catch (Java.IO.IOException e)
                {
                    Log.Error(TAG, "listen() failed", e);
                }
                serverSocket  = tmp;
                service.state = STATE_LISTEN;
            }
コード例 #6
0
            public AcceptThread(BluetoothChatService chatService, bool secure)
            {
                this.chatService = chatService;
                BluetoothServerSocket tmp = null;

                mSocketType = secure ? "Secure":"Insecure";

                // Create a new listening server socket
                try
                {
                    if (secure)
                    {
                        tmp = chatService.mAdapter.ListenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE);
                    }
                    else
                    {
                        tmp = chatService.mAdapter.ListenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE);
                    }
                }
                catch (IOException e)
                {
                    Log.E(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
                }
                mmServerSocket = tmp;
            }
コード例 #7
0
        public void ReceivePair()
        {
            Task.Run(() =>
            {
                if (BtAdapter.IsEnabled && !ReceivingConnection)
                {
                    BluetoothServerSocket tmp = null;
                    try
                    {
                        // MY_UUID is the app's UUID string, also used by the client code.
                        tmp = BtAdapter.ListenUsingRfcommWithServiceRecord("BattleShots", UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));
                    }
                    catch (Exception e)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            ToastLoader toastLoader = new ToastLoader();
                            toastLoader.Show(e.Message);
                        });
                    }
                    mmServerSocket      = tmp;
                    ReceivingConnection = true;

                    CheckForPair();
                }
            });
        }
コード例 #8
0
 private void DoStopAdvertising()
 {
     if (_socket != null)
     {
         _socket.Close();
         _socket = null;
     }
 }
コード例 #9
0
ファイル: BTAcceptThread.cs プロジェクト: sorke/GridDominance
        public BTAcceptThread(XamarinBluetooth a)
        {
            _adapter = a;
            BluetoothServerSocket tmp = null;

            // Create a new listening server socket

            tmp = _adapter.Adapter.ListenUsingRfcommWithServiceRecord(XamarinBluetooth.NAME, XamarinBluetooth.UUID);

            mmServerSocket = tmp;
        }
コード例 #10
0
            public AcceptThread(BluetoothService service)
            {
                _service = service;
                BluetoothServerSocket tmp = null;

                // Create a new listening server socket
                try {
                    tmp = _service._adapter.ListenUsingRfcommWithServiceRecord(NAME, MY_UUID);
                } catch (Java.IO.IOException e) {
                    Log.Error(TAG, "listen() failed", e);
                }
                mmServerSocket = tmp;
            }
コード例 #11
0
        public void acceptThread()
        {
            BluetoothServerSocket temp = null;

            try
            {
                temp = btAdapter.ListenUsingRfcommWithServiceRecord("ShareTheMusic", uuid);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Socket's listen() method failed", ex);
            }
            mServerSocket = temp;
        }
コード例 #12
0
ファイル: BluetoothService.cs プロジェクト: matcodes/OAK
        private void RunAccept(bool isAndroid)
        {
            Task.Run(() => {
                try
                {
                    var uuid            = (isAndroid ? UUID_ANDROID_DEVICE : UUID_OTHER_DEVICE);
                    _acceptServerSocket = _adapter.ListenUsingRfcommWithServiceRecord(NAME_SECURITY, uuid);
                }
                catch (IOException)
                {
                }

                _isAcceptRunning = true;

                BluetoothSocket socket = null;

                while ((this.State != BluetoothState.STATE_CONNECTED) && (_isAcceptRunning))
                {
                    try
                    {
                        socket = _acceptServerSocket.Accept();
                    }
                    catch (IOException)
                    {
                        break;
                    }

                    if (socket != null)
                    {
                        lock (_acceptLocket)
                        {
                            if ((this.State == BluetoothState.STATE_LISTEN) || (this.State == BluetoothState.STATE_CONNECTING))
                            {
                                //                               this.Connected(socket, socket.RemoteDevice);
                            }
                            else if ((this.State == BluetoothState.STATE_CONNECTED) || (this.State == BluetoothState.STATE_NONE))
                            {
                                try
                                {
                                    socket.Close();
                                }
                                catch (IOException)
                                {
                                }
                            }
                        }
                    }
                }
            });
        }
コード例 #13
0
            //private readonly string mSocketType;

            public AcceptThread()
            {
                BluetoothServerSocket tmp = null;

                //创建新的侦听服务器套接字
                try
                {
                    tmp = mAdapter.ListenUsingInsecureRfcommWithServiceRecord(NAME, MY_UUID);
                }
                catch (Exception)
                {
                    //Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
                }
                mmServerSocket = tmp;
            }
コード例 #14
0
ファイル: BluetoothService.cs プロジェクト: matcodes/OAK
 private void CancelAccept()
 {
     try
     {
         _isAcceptRunning = false;
         if (_acceptServerSocket != null)
         {
             _acceptServerSocket.Close();
             _acceptServerSocket = null;
         }
     }
     catch (IOException)
     {
     }
 }
コード例 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BTLibrary.BTListenThread"/> class.
        /// </summary>
        /// <param name="NAME">Name.</param>
        /// <param name="MY_UUID">My UUID.</param>
        internal BTListenThread(string NAME, UUID MY_UUID)
        {
            BluetoothServerSocket tmp = null;

            try {
                tmp = BTManager.Instance.getBTAdapter().ListenUsingRfcommWithServiceRecord(NAME, MY_UUID);
            } catch {
            }

            //start the thread
            _serverSocket  = tmp;
            _Listener      = new Thread(Listen);
            _Listener.Name = "ListenThread";
            _Listener.Start();
        }
コード例 #16
0
        public BluetoothController(Activity activity)
        {
            _adapter  = BluetoothAdapter.DefaultAdapter;
            _activity = activity;
            _listener = _adapter.ListenUsingRfcommWithServiceRecord(BluetoothName, ID);
            //_scanner = new System.Timers.Timer ();
            //_scanner.Elapsed += (sender, e) => HandleScan();
            //_scanner.Interval = TimeSpan.FromSeconds (5).TotalMilliseconds;

            var filter = new IntentFilter(BluetoothDevice.ActionFound);

            activity.RegisterReceiver(this, filter);
            activity.RegisterReceiver(this, new IntentFilter(BluetoothAdapter.ActionScanModeChanged));
            activity.RegisterReceiver(this, new IntentFilter(BluetoothAdapter.ActionDiscoveryFinished));
        }
コード例 #17
0
        public AcceptThread(BluetoothService service)
        {
            this.service = service;
            BluetoothServerSocket tempSocket = null;

            try
            {
                BluetoothAdapter adapter = this.service.BtAdapter;
                tempSocket = adapter.ListenUsingInsecureRfcommWithServiceRecord(service.BtName, service.MyUUID);
            }
            catch (IOException e)
            {
                Logger.Log("Socket's listen() method failed " + e.Message);
            }

            serverSocket = tempSocket;
        }
コード例 #18
0
            public AcceptThread()
            {
                // Use a temporary object that is later assigned to mmServerSocket
                // because mmServerSocket is final.
                BluetoothServerSocket tmp = null;

                try
                {
                    // MY_UUID is the app's UUID string, also used by the client code.
                    tmp = Bth.mBluetoothAdapter.ListenUsingRfcommWithServiceRecord("NAME", MY_UUID);
                }
                catch (Java.IO.IOException e)
                {
                    System.Console.WriteLine("Errore: " + e);
                }
                mmServerSocket = tmp;
            }
コード例 #19
0
ファイル: MainActivity.cs プロジェクト: msthrax/BLEApp
            public bool ConnectToDeviceByName(string crossBluetoothDeviceName)
            {
                bool result = false;

                if (deviceList.Count > 0 || bluetoothAdapter.BondedDevices.Count > 0)
                {
                    var pairedDeviceSearchCount     = bluetoothAdapter.BondedDevices.Where(x => x.Name == crossBluetoothDeviceName).Count();
                    var discoveredDeviceSearchCount = deviceList.Where(x => x.Name == crossBluetoothDeviceName).Count();
                    if (pairedDeviceSearchCount > 0)
                    {
                        if (pairedDeviceSearchCount == 1)
                        {
                            var bluetoothDevice = bluetoothAdapter.BondedDevices.First(x => x.Name == crossBluetoothDeviceName);
                            bluetoothTxSocket = bluetoothDevice.CreateRfcommSocketToServiceRecord(UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));
                            bluetoothTxSocket.Connect();
                            streamWriter = bluetoothTxSocket.OutputStream;

                            bluetoothServerSocket = bluetoothAdapter.ListenUsingRfcommWithServiceRecord(context.PackageName, UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));
                            bluetoothRxSocket     = bluetoothServerSocket.Accept();
                            streamReader          = bluetoothRxSocket.InputStream;
                            result = true;
                            int i = 0;
                        }
                    }
                    else
                    {
                        if (discoveredDeviceSearchCount > 0)
                        {
                            if (discoveredDeviceSearchCount == 1)
                            {
                                var bluetoothDevice = deviceList.First(x => x.Name == crossBluetoothDeviceName);
                                bluetoothTxSocket = bluetoothDevice.CreateRfcommSocketToServiceRecord(UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));
                                bluetoothTxSocket.Connect();
                                streamWriter = bluetoothTxSocket.OutputStream;

                                bluetoothServerSocket = bluetoothAdapter.ListenUsingRfcommWithServiceRecord(context.PackageName, UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));
                                bluetoothRxSocket     = bluetoothServerSocket.Accept();
                                streamReader          = bluetoothRxSocket.InputStream;
                                result = true;
                                int i = 0;
                            }
                        }
                    }
                }
                return(result);
            }
コード例 #20
0
            public AcceptThread(BluetoothAdapter _btAdpt)
            {
                BluetoothServerSocket bss = null;

                btAdpt = _btAdpt;

                try
                {
                    bss = btAdpt.ListenUsingRfcommWithServiceRecord(Constants.APP_NAME, Constants.APP_UUID);
                }
                catch (Java.IO.IOException e)
                {
                    e.PrintStackTrace();
                }

                btServerSocket = bss;
            }
コード例 #21
0
            public AcceptThread(BluetoothService service)
            {
                BluetoothServerSocket tmp = null;

                this.service = service;

                try
                {
                    tmp = service.btAdapter.ListenUsingRfcommWithServiceRecord(App_Name, uUID);
                }
                catch (Exception e)
                {
                    Toast.MakeText(Application.Context, "Listening Failed due to " + e.Message, ToastLength.Long).Show();
                }
                serverSocket  = tmp;
                service.state = ConnectionState.Listen;
            }
コード例 #22
0
        protected override void UpdateLoop()
        {
            if (currentAction == Actions.None)
            {
                return;
            }

            try
            {
                switch (currentAction)
                {
                case Actions.ListenForTeam:
                    ListenForTeam();
                    break;

                case Actions.ListenForDataSetInfo:
                    ListenForDataSetInfo();
                    break;

                case Actions.ReceiveDataSet:
                    ReceiveDataSet();
                    break;

                case Actions.WriteRoundData:
                    WriteRoundData();
                    break;
                }
            }
            catch (Exception ex)
            {
                #if DEBUG
                Log.Error("MyScout", $"ERROR: {ex.Message}");
                #endif

                socket       = null;
                serverSocket = BluetoothIO.Adapter.ListenUsingRfcommWithServiceRecord(
                    "MyScout_Scout", MyScoutUUID);
            }

            // Start listening for team data if ready
            if (startListeningOnceDone)
            {
                StartListening();
            }
        }
コード例 #23
0
            public AcceptThread(BluetoothConnectionService service)
            {
                this.service = service;
                BluetoothServerSocket tmp = null;

                // create a listening server socket
                try
                {
                    tmp = service.bluetoothAdapter.ListenUsingInsecureRfcommWithServiceRecord(appName, MY_UUID_INSECURE);
                    Logger.Log("AcceptThread: Setting up Service using " + MY_UUID_INSECURE);
                }
                catch (IOException e)
                {
                    Logger.Log("AcceptThread: " + e.Message);
                }

                serverSocket = tmp;
            }
コード例 #24
0
        public void Start()
        {
            var svcName = ServiceName;

            Debug.Assert(_svcClassOrig != null, "NULL _svcClassOrig");
            Debug.Assert(_svcClass != null, "NULL _svcClass");
            var uuid = _svcClass;
            var a    = _fcty.GetAdapter();

            if (_auth || _encr)
            {
                _server = a.ListenUsingRfcommWithServiceRecord(svcName, uuid);
            }
            else
            {
                _server = a.ListenUsingInsecureRfcommWithServiceRecord(svcName, uuid);
            }
            _server.ToString(); // ensure non-null
            _active = true;
        }
コード例 #25
0
            public AcceptThread(OBDConnectionService service)
            {
                _service = service;
                BluetoothServerSocket tmp = null;

                // Create a new listening server socket
                try
                {
#if (TO_PHONE)
                    tmp = _service._adapter.ListenUsingRfcommWithServiceRecord(NAME, MY_UUID_PHONE);
#endif
#if (TO_OBD)
                    tmp = _service._adapter.ListenUsingRfcommWithServiceRecord(NAME, MY_UUID_OBD);
#endif
                }
                catch (Java.IO.IOException e)
                {
                    Log.Error(TAG, "listen() failed", e);
                }
                mmServerSocket = tmp;
            }
コード例 #26
0
        private async void StartAccepting()
        {
            UUID uuid = UUID.FromString("6c460207-cba2-43ac-acb9-daf481d10f95");

            if (server != null)
            {
                server.Close();
            }
            server = bluetoothAdapter.ListenUsingRfcommWithServiceRecord("LakesideLounge", uuid);

            if (socket != null && socket.IsConnected)
            {
                socket.Close();
            }

            while (true)
            {
                await Task.Run(() => socket = server.Accept());

                StartRecieving();
            }
        }
コード例 #27
0
        public override async Task <VoidResult <SocketOperationStatus> > Start()
        {
            await Task.Yield();

            if (!IsActive)
            {
                try
                {
                    ServerSocket = ConnectionProvider.Adapter.InternalDevice.ListenUsingInsecureRfcommWithServiceRecord("Name?", Port.ToUUID());
                    IsActive     = true;
                    return(new VoidResult <SocketOperationStatus>(SocketOperationStatus.Success, null));
                }
                catch (Exception ex)
                {
                    return(new VoidResult <SocketOperationStatus>(SocketOperationStatus.UnknownError, ex));
                }
            }
            else
            {
                return(new VoidResult <SocketOperationStatus>(SocketOperationStatus.ListenerIsAlreadyStarted, null));
            }
        }
コード例 #28
0
 /// <summary>
 /// Creates a new listener.
 /// </summary>
 /// <param name="instance">The <see cref="ErebusInstance"/> that this listener provides connections to.</param>
 public BluetoothConnectionListener(ErebusInstance instance)
 {
     ei = instance;
     l  = BluetoothAdapter.DefaultAdapter.ListenUsingRfcommWithServiceRecord("ErebusConnection", BluetoothUtils.RfcommConnectionService);
     lt = listenProcess();
 }
コード例 #29
0
        // Setup server
        private void StartServer_Clicked(object sender, EventArgs e)
        {
            _clientMode = false;

            if (_bluetoothAdapter != null)
            {
                _bluetoothServerSocket = _bluetoothAdapter.ListenUsingRfcommWithServiceRecord(_myName, _myUUID);

                _serverThread = new BluetoothServer(this, _bluetoothServerSocket, _carouselPage);

                ThreadStart             WaitForConnectionFunc = new ThreadStart(_serverThread.WaitForConnection);
                System.Threading.Thread waitForConnectThread  = new System.Threading.Thread(WaitForConnectionFunc);
                waitForConnectThread.IsBackground = true;
                waitForConnectThread.Start();

                ThreadStart             myThreadDelegate = new ThreadStart(_serverThread.ListenForBTData);
                System.Threading.Thread myThread         = new System.Threading.Thread(myThreadDelegate);
                myThread.IsBackground = true;
                myThread.Start();

                #region Gartner For CIO's
                var GartnerForCIOs        = new ContentPage();
                var ContentGartnerForCIOs = new StackLayout();
                ContentGartnerForCIOs.VerticalOptions = LayoutOptions.Start;

                Label PP1 = new Label();
                PP1.FontSize                = _fontSizeMed;
                PP1.FontAttributes          = FontAttributes.Italic;
                PP1.HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Start;
                PP1.TextColor               = Color.Teal;
                PP1.BackgroundColor         = Color.Silver;
                PP1.Text = "  Gartner for CIO's";

                Label PP2 = new Label();
                PP2.FontSize = _fontSizeSmall;
                PP2.HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Start;
                PP2.Text = " ";

                Label PP3 = new Label();
                PP3.FontSize = _fontSizeLarge;
                PP3.HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Start;
                PP3.Text = "   Cost Optimization Tools";

                Label SpacerPay2 = new Label();
                SpacerPay2.FontSize = _fontSizeMicro;
                SpacerPay2.HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Start;
                SpacerPay2.Text = " ";

                Label PP4 = new Label();
                PP4.FontSize = _fontSizeLarge;
                PP4.HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Start;
                PP4.Text = "   Contract Review Service";

                Label SpacerPay3 = new Label();
                SpacerPay3.FontSize = _fontSizeMicro;
                SpacerPay3.HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Start;
                SpacerPay3.Text = " ";

                Label PP5 = new Label();
                PP5.FontSize = _fontSizeLarge;
                PP5.HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Start;
                PP5.Text = "   Research Tools";

                Label SpacerPay4 = new Label();
                SpacerPay4.FontSize = _fontSizeMicro;
                SpacerPay4.HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Start;
                SpacerPay4.Text = " ";

                Label PP6 = new Label();
                PP6.FontSize = _fontSizeLarge;
                PP6.HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Start;
                PP6.Text = "   Executive Partner";

                ContentGartnerForCIOs.Children.Add(PP1);
                ContentGartnerForCIOs.Children.Add(PP2);
                ContentGartnerForCIOs.Children.Add(PP3);
                ContentGartnerForCIOs.Children.Add(SpacerPay2);
                ContentGartnerForCIOs.Children.Add(PP4);
                ContentGartnerForCIOs.Children.Add(SpacerPay3);
                ContentGartnerForCIOs.Children.Add(PP5);
                ContentGartnerForCIOs.Children.Add(SpacerPay4);
                ContentGartnerForCIOs.Children.Add(PP6);
                GartnerForCIOs.Content = ContentGartnerForCIOs;
                GartnerForCIOs.AnchorX = 4;

                int indexNavPage = _carouselPage.Children.IndexOf(_navigationPage);
                _carouselPage.Children.Remove(_navigationPage);
                _carouselPage.Children.Insert(indexNavPage, GartnerForCIOs);
                #endregion
            }
        }
コード例 #30
0
 // Constructors
 public ScoutConnection(BluetoothAdapter adapter)
 {
     serverSocket = adapter.ListenUsingRfcommWithServiceRecord(
         "MyScout_Scout", MyScoutUUID);
 }