示例#1
0
 private void bluetooth_Closing(object sender, CancelEventArgs e)
 {
     if (mObexListener != null)
     {
         mObexListener.Stop();
     }
 }
示例#2
0
        public async void ReceiveFile()
        {
            if (BluetoothRadio.IsSupported)
            {
                if (numReceiving < 6)
                {
                    statusDisplay.Text = (++numReceiving).ToString();
                    BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
                    await Task.Run(() => {
                        ObexListener listener = new ObexListener(ObexTransport.Bluetooth);
                        listener.Start();
                        ObexListenerContext context = listener.GetContext();
                        ObexListenerRequest request = context.Request;
                        string[] pathSplits         = request.RawUrl.Split('/');
                        string fileName             = pathSplits[pathSplits.Length - 1];
                        request.WriteFile(filePath + fileName);
                        listener.Stop();
                        listener.Close();
                    });

                    statusDisplay.Text = (--numReceiving).ToString();
                }
                else
                {
                    MessageBox.Show("Number of pending transfers is limited to 6", "FYI", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                MessageBox.Show("Bluetooth must be enabled on your device for this function to work", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#3
0
        private void DoTestStartStopStart(ObexListener lsnr)
        {
            Action <ObexListener> dlgt = Foo;

            lsnr.Start();
            IAsyncResult ar0 = dlgt.BeginInvoke(lsnr, null, null);

            Assert.IsFalse(ar0.IsCompleted);
            lsnr.Stop();
            System.Threading.Thread.Sleep(50);
            Assert.IsTrue(ar0.IsCompleted);
            lsnr.Start();
            try {
                dlgt.EndInvoke(ar0);
            } catch (InvalidOperationException) {
            }
            lsnr.Stop();
        }
示例#4
0
 private void buttonListen_Click(object sender, EventArgs e)
 {
     if (listener == null || !listener.IsListening)
     {
         radio.Mode = RadioMode.Discoverable;                    //设置本地蓝牙可被检测
         listener   = new ObexListener(ObexTransport.Bluetooth); //创建监听
         listener.Start();
         if (listener.IsListening)
         {
             buttonListen.Text = "停止";
             labelRecInfo.Text = "开始监听";
             listenThread      = new Thread(receiveFile);//开启监听线程
             listenThread.Start();
         }
     }
     else
     {
         listener.Stop();
         buttonListen.Text = "监听";
         labelRecInfo.Text = "停止监听";
     }
 }
 static private void listen()
 {
     while (true)
     {
         var listener = new ObexListener(ObexTransport.Bluetooth);
         listener.Start();
         ObexListenerContext con        = listener.GetContext();
         ObexListenerRequest req        = con.Request;
         String[]            pathSplits = req.RawUrl.Split('/');
         String filename = pathSplits[pathSplits.Length - 1];
         req.WriteFile(filename);
         listener.Stop();
     }
 }
示例#6
0
        private void buttonReceive_Click(object sender, EventArgs e)
        {
            ObexListener listener = new ObexListener();

            listener.Start();
            ObexListenerContext context = listener.GetContext();
            ObexListenerRequest request = context.Request;

            String[] pathSplits = request.RawUrl.Split('/');
            String   filename   = pathSplits[pathSplits.Length - 1];

            request.WriteFile(filename);
            listener.Stop();
        }
示例#7
0
 // Funkcja pozwalająca na odbieranie plików
 private void ReceiveFiles()
 {
     while (isPaired)
     {
         var listener = new ObexListener(ObexTransport.Bluetooth);
         listener.Start();
         ObexListenerContext ctx        = listener.GetContext();
         ObexListenerRequest req        = ctx.Request;
         String[]            pathSplits = req.RawUrl.Split('/');
         String file = pathSplits[pathSplits.Length - 1];
         req.WriteFile(file);
         textBoxConsole.Text += "Odebrano plik.\r\n";
         listener.Stop();
     }
 }
示例#8
0
        void ObexSvr1()
        {
            var lsnr = new ObexListener(ObexTransport.Bluetooth);

            lsnr.Start();
            // For each connection
            ObexListenerContext ctx = lsnr.GetContext();
            ObexListenerRequest req = ctx.Request;

            String[] pathSplits = req.RawUrl.Split('/');
            String   filename   = pathSplits[pathSplits.Length - 1];

            req.WriteFile(filename);
            //
            lsnr.Stop();
        }
示例#9
0
        private void ReceiveFile()
        {
            textBox1.Text += ("Rozpoczynam nasluchiwanie na nowe wiadomosci...") + Environment.NewLine;

            // wykonuje do momenu gdy nie zostaniemy rozlaczeni z urzadzeniem
            while (czySparowano)
            {
                var listener = new ObexListener(ObexTransport.Bluetooth);
                listener.Start();
                ObexListenerContext ctx        = listener.GetContext();
                ObexListenerRequest req        = ctx.Request;
                String[]            pathSplits = req.RawUrl.Split('/');
                String filename = pathSplits[pathSplits.Length - 1];
                req.WriteFile(filename);
                textBox1.Text += (filename);
                listener.Stop();
            }
        }
示例#10
0
        //static string BytesToHexAlpha(byte[] bytes)
        //{
        //	StringBuilder sb = new StringBuilder();
        //	foreach(byte b in bytes) {
        //		char c = Convert.ToChar(b);
        //		if (!Char.IsControl(c)) {
        //			sb.Append(c);
        //		} else {
        //			sb.Append(".");
        //		}
        //	}
        //	return sb.ToString();
        //}

        static void ReceiveFiles()
        {
            BluetoothRadio br = BluetoothRadio.PrimaryRadio;

            if (br == null)
            {
                Console.WriteLine("No BlueTooth radio found");
                return;
            }

            if (br.Mode != RadioMode.Discoverable)
            {
                br.Mode = RadioMode.Discoverable;
            }

            var listener = new ObexListener(ObexTransport.Bluetooth);

            listener.Start();
            Console.WriteLine("Listening for files... press any key to stop");

            //need to use another thread since we have two blocking calls
            var stopit = Task.Factory.StartNew(() => {
                Console.ReadKey(true);                 //blocks
                listener.Stop();
            });

            while (listener.IsListening)
            {
                try {
                    var olc = listener.GetContext();                     //blocks
                    var olr = olc.Request;

                    string filename = Uri.UnescapeDataString(olr.RawUrl.TrimStart(new char[] { '/' }));
                    string final    = DateTime.Now.ToString("yyMMddHHmmss") + "-" + filename;
                    olr.WriteFile(final);
                    Console.WriteLine("Wrote " + final);
                } catch (Exception e) {
                    e.ToString();
                    break;
                }
            }
        }
示例#11
0
 public void OperateListener()
 {
     if (listener == null || !listener.IsListening)
     {
         radio.Mode = RadioMode.Discoverable;                    //设置本地蓝牙可被检测
         listener   = new ObexListener(ObexTransport.Bluetooth); //创建监听
         listener.Start();
         if (listener.IsListening)
         {
             Console.WriteLine("开始监听");
             listenThread = new Thread(receiveFile);//开启监听线程
             listenThread.Start();
         }
     }
     else
     {
         listener.Stop();
         Console.WriteLine("停止监听");
     }
 }
示例#12
0
        private void createObexListener()
        {
            UpdateBTDeviceDetails("Create Bluetooth Obex Listener");
            DisplayBluetoothRadio();
            if (mBluetoothRadio == null)
            {
                UpdateBTDeviceDetails("No support Bluetooth radio/stack found.");
                return;
            }
            else if (mBluetoothRadio.Mode != InTheHand.Net.Bluetooth.RadioMode.Discoverable)
            {
                DialogResult rslt = MessageBox.Show("Make BluetoothRadio Discoverable?", "DeviceListener", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (rslt == DialogResult.Yes)
                {
                    mBluetoothRadio.Mode = InTheHand.Net.Bluetooth.RadioMode.Discoverable;
                }
                else
                {
                    return;
                }
            }

            mObexListener = new ObexListener(ObexTransport.Bluetooth);
            if (!serviceStarted)
            {
                serviceStarted = true;
                mObexListener.Start();
                System.Threading.Thread mThread = new System.Threading.Thread(new System.Threading.ThreadStart(DealWithRequest));
                mThread.IsBackground = true;
                mThread.Start();
                UpdateBTDeviceDetails("Bluetooth Obex Listener started.");
            }
            else
            {
                serviceStarted = false;
                mObexListener.Stop();
                UpdateBTDeviceDetails("Bluetooth Obex Listener stopped.");
            }
        }
示例#13
0
        public MemoryStream IniciarRecepcionImagenBT()
        {
            MemoryStream archivo = new MemoryStream();

            BluetoothRadio radio = BluetoothRadio.PrimaryRadio;

            if (radio == null)
            {
                throw new Exception("No bluetooth device connected");
            }
            else
            {
                radio.Mode = RadioMode.Discoverable;
            }


            ObexListener receptorImagenes = new ObexListener(ObexTransport.Bluetooth);

            receptorImagenes.Start();
            //MessageBox.Show("Esperando imagen", "Receptor Imagenes", MessageBoxButtons.OK);
            ObexListenerContext contexto = receptorImagenes.GetContext();
            //MessageBox.Show("Imagen Recibida", "Receptor Imagenes", MessageBoxButtons.OK);

            ObexListenerRequest req = contexto.Request;

            string archivoDireccion = req.RawUrl;
            string extension        = req.RawUrl.Split('.').ToList().LastOrDefault();

            archivo = new MemoryStream();
            req.InputStream.CopyTo(archivo);
            string b64 = Convert.ToBase64String(archivo.ToArray());

            //req.WriteFile("."+ archivoDireccion);
            //File.WriteAllBytes("./b64." + extension, archivo.ToArray());
            receptorImagenes.Stop();

            return(archivo);
        }
示例#14
0
        /// <summary>
        /// Receive (fetch) a file from an attached external bluetooth device.
        /// You must first Initialise, then set the device.
        /// </summary>
        /// <param name="fileName">The location to save the received file.</param>
        /// <returns>A result status message "True" or "False".</returns>
        public static Primitive ReceiveFile(Primitive fileName)
        {
            BluetoothDeviceInfo info = GetBluetoothDeviceInfo(device);

            if (null == info || null == bluetoothClient)
            {
                lastError = "Device or client not set";
                return("False");
            }
            try
            {
                ObexListener ol = new ObexListener(ObexTransport.Bluetooth);
                ol.Start();
                while (ol.IsListening)
                {
                    try
                    {
                        ObexListenerContext olc = ol.GetContext();
                        ObexListenerRequest olr = olc.Request;
                        olr.WriteFile(fileName);
                        ol.Stop();
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        lastError = ex.Message;
                        return("False");
                    }
                }
                return("True");
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                lastError = ex.Message;
                return("False");
            }
        }
示例#15
0
 private void ListenerForm_Closed(object sender, System.EventArgs e)
 {
     ol.Stop();
 }
示例#16
0
文件: Form1.cs 项目: jehy/32feet.NET
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            listener.Stop();

            base.OnClosing(e);
        }