/*public void searchForDevices() * { * while (true) * { * BluetoothDeviceInfo[] array = bc.DiscoverDevices(); * foreach (BluetoothDeviceInfo bti in array) * { * fileList.Items.Add(bti.DeviceName); * } * fileList.Clear(); * } * * }*/ public BlueTube() { InitializeComponent(); request = initializeYoutube(); picasaService = initializePicasa(); ol = new ObexListener(ObexTransport.Bluetooth); bc = new InTheHand.Net.Sockets.BluetoothClient(); try { ol.Start(); } catch (Exception e) { Console.WriteLine(e); System.Windows.Forms.MessageBox.Show("Bluetube failed to start, enable a compatible bluetooth adapter"); Environment.Exit(0); } Thread t1 = new Thread(new System.Threading.ThreadStart(DealWithRequest)); t1.Start(); //BluetoothDeviceInfo[] array = bc.DiscoverDevices(); //deviceList.Items.Add(""+array.Length); //for (int i = 0; i < array.Length; i++) //{ // deviceList.Items.Add(array[i].DeviceName); //} }
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); } }
void Foo(ObexListener lsnr) { ObexListenerContext ctx = lsnr.GetContext(); if (ctx != null) { ObexListenerRequest req = ctx.Request; } }
public void StartStopStart() { ObexListener lsnr; lsnr = new ObexListener(ObexTransport.Tcp); DoTestStartStopStart(lsnr); lsnr = new ObexListener(ObexTransport.Bluetooth); DoTestStartStopStart(lsnr); // With Window's Irmon service running we can't run another IrDA OBEX service. //lsnr = new ObexListener(ObexTransport.IrDA); //DoTestStartStopStart(lsnr); }
public static async Task <ObexListenerContext> GetContextAsync(this ObexListener obexListener, int timeout) { var task = Task.Run(() => obexListener.GetContext()); if (await Task.WhenAny(task, Task.Delay(timeout)) == task) { return(task.Result); } else { throw new TimeoutException(); } }
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(); } }
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(); }
// 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(); } }
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(); }
public void StartObexListener() { radio = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio; if (radio != null) { Console.WriteLine("Bluetooth radio on."); radio.Mode = InTheHand.Net.Bluetooth.RadioMode.Discoverable; listener = new ObexListener(ObexTransport.Bluetooth); listener.Start(); dispatcher = Dispatcher.CurrentDispatcher; System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ObexRequestHandler)); t.Start(); } }
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(); } }
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(); }
//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; } } }
public Form1() { InitializeComponent(); InTheHand.Net.Bluetooth.BluetoothRadio br = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio; if (br == null) { MessageBox.Show("No support Bluetooth radio/stack found."); } else if (br.Mode != InTheHand.Net.Bluetooth.RadioMode.Discoverable) { DialogResult rslt = MessageBox.Show("Make BluetoothRadio Discoverable?", "DeviceListener", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (rslt == DialogResult.Yes) { br.Mode = InTheHand.Net.Bluetooth.RadioMode.Discoverable; } } listener = new ObexListener(ObexTransport.Bluetooth); items = new ArrayList(); }
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("停止监听"); } }
public ListenerForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // InTheHand.Net.Bluetooth.BluetoothRadio br = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio; if (br == null) { MessageBox.Show("No support Bluetooth radio/stack found."); } else if (br.Mode != InTheHand.Net.Bluetooth.RadioMode.Discoverable) { DialogResult rslt = MessageBox.Show("Make BluetoothRadio Discoverable?", "DeviceListener", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (rslt == DialogResult.Yes) { br.Mode = InTheHand.Net.Bluetooth.RadioMode.Discoverable; } } /* * InTheHand.Net.Forms.SelectBluetoothDeviceDialog sbdd = new InTheHand.Net.Forms.SelectBluetoothDeviceDialog(); * sbdd.Info = "Oh just pick one, they are all the same!"; * if (sbdd.ShowDialog() == DialogResult.OK) * { * * * byte[] rec = sbdd.SelectedDevice.GetServiceRecord(InTheHand.Net.Bluetooth.BluetoothService.SerialPort); * * }*/ ol = new ObexListener(ObexTransport.Bluetooth); ol.Start(); }
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."); } }
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 = "停止监听"; } }
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); }
/// <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"); } }
/// <summary> /// Initialise a new instance of the <see cref="T:InTheHand.Net.ObexListener"/> class, /// using the respective stack and/or radio. /// </summary> /// - /// <returns>The new instance of <see cref="T:InTheHand.Net.ObexListener"/>. /// </returns> public ObexListener CreateObexListener() { ObexListener req = new ObexListener(this); return(req); }
public static ObexListenerContext GetContext(this ObexListener listener, int timeout) { var task = Task.Run(async() => await listener.GetContextAsync(timeout)); return(task.Result); }