Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Threading;
- using System.IO;
- using System.Collections.ObjectModel;
- using System.Windows.Threading;
- using InTheHand;
- using InTheHand.Net.Bluetooth;
- using InTheHand.Net.Ports;
- using InTheHand.Net.Sockets;
- using InTheHand.Net;
- namespace ObexServer
- {
- class Server
- {
- static private ObexListener listener;
- static private Dispatcher dispatcher;
- static private BluetoothRadio radio;
- static private void StartObexListener()
- {
- radio = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio;
- if (radio != null)
- {
- 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();
- }
- Console.ReadLine();
- }
- static private void ObexRequestHandler()
- {
- if (radio == null)
- return;
- Console.WriteLine(radio);
- while (listener.IsListening)
- {
- try
- {
- ObexListenerContext olc = listener.GetContext();
- ObexListenerRequest olr = olc.Request;
- string filename = "E:\\igreen\\upload\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "_" + Uri.UnescapeDataString(olr.RawUrl.TrimStart(new char[] { '/' }));
- Console.WriteLine(filename);
- olr.WriteFile(filename);
- dispatcher.Invoke(new Action(delegate()
- {
- // Photos.Add(filename);
- // OnPropertyChanged("HasPhotos");
- }));
- }
- catch (Exception ex)
- {
- break;
- }
- }
- }
- static void Main(string[] args)
- {
- StartObexListener();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement