Exemple #1
0
        public void L2capCliConnect()
        {
            var cli = new L2CapClient();
            BluetoothEndPoint epNull = null;

            try {
                var task = cli.ConnectAsync(epNull, null);
                Assert.Fail("expected exception");
            } catch (ArgumentException) {
            }
        }
Exemple #2
0
        public void L2CapConnect()
        {
            BluetoothAddress addr      = console.ReadBluetoothAddress("Server's BluetoothAddress");
            Guid             svcClass  = SvcClassForL2CapTests;
            Guid?            inputGuid = console.ReadOptionalBluetoothUuid("UUID", svcClass);

            if (inputGuid.HasValue)
            {
                svcClass = inputGuid.Value;
            }
            int?port = console.ReadOptionalInteger("Port number (L2CAP PSM)");

            // to-do: auth/encrypt/setpin
            bool@async = true; //console.ReadYesNo("Async Connect?", false);
            bool asyncCallback = true;
            //if @async) {
            //    asyncCallback = console.ReadYesNo("Async Callback?", true);
            //}
            //
            BluetoothEndPoint rep;

            if (port == null)
            {
                rep = new BluetoothEndPoint(addr, svcClass);
            }
            else
            {
                rep = new BluetoothEndPoint(addr, svcClass, port.Value);
            }
            console.WriteLine("Connecting to: {0}:{1}:{2} ...", rep.Address, rep.Service, rep.Port);
            //
            var cli = new L2CapClient();

            if (@async)
            {
                AsyncCallback cb = null;
                if (asyncCallback)
                {
                    cb = MiscCallback;
                }
                IAsyncResult ar = cli.BeginConnect(rep,
                                                   cb, "BeginConnect");
                console.WriteLine("(BeginConnect returned)");
#if NETCF // ReadYesNo will block the screen. :-(
                console.Pause("Paused after BeginConnect");
#endif
                bool closeNow = console.ReadYesNo("Respond when we should proceed to EndConnect.  Enter Y to call Close first.", false);
                if (closeNow)
                {
                    cli.Close();
                }
                cli.EndConnect(ar);
            }
            else
            {
                cli.Connect(rep);
            }
            console.WriteLine("Connected to : {0}", cli.RemoteEndPoint);
            //PrintLocalEndpointIfAvailable(cli);
            PrintMtuEtc(cli);
            //----
            _peer     = cli.GetStream();
            _cliL2Cap = new WeakReferenceT <L2CapClient>(cli);
        }
Exemple #3
0
        //--------
        private void PrintMtuEtc(L2CapClient cli)
        {
            var mtu = cli.GetMtu();

            console.WriteLine("MTU (their MRU): {0}.", mtu);
        }