蓝牙传输

时间:2017-04-22 17:25:11

标签: c# wpf bluetooth 32feet obex

我正在尝试制作一个程序,将文件发送到加密的移动设备,然后设备会将其传入另一个程序并对其进行解密。

到目前为止,我已经完成了蓝牙连接:

private void Connect()
{
    using (SelectBluetoothDeviceDialog bldialog = new SelectBluetoothDeviceDialog())
    {
        bldialog.ShowAuthenticated = true;
        bldialog.ShowRemembered = true;
        bldialog.ShowUnknown = true;

        if (bldialog.ShowDialog() == System.Windows.Forms.DialogResult.OK )
        {
            if (bldialog.SelectedDevice == null)
            {
                System.Windows.Forms.MessageBox.Show("No device selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            BluetoothDeviceInfo selecteddevice = bldialog.SelectedDevice;
            BluetoothEndPoint remoteEndPoint = new BluetoothEndPoint(selecteddevice.DeviceAddress, BluetoothService.ObexFileTransfer);

            client = new BluetoothClient();
            client.Connect(remoteEndPoint);

            session = new ObexClientSession(client.GetStream(), UInt16.MaxValue);
            session.Connect(ObexConstant.Target.FolderBrowsing);
            tbConnectionDet.Text = string.Format("Connected to: {0}", selecteddevice.DeviceName);
        }
    }
}

我也是这样发送文件的:

 private void UploadFiles(string[] files)
    {
        long size = 0;
        List<string> filestoupload = new List<string>();

        foreach (string filename in files)
        {
            if (File.Exists(filename))
            {
                FileInfo info = new FileInfo(filename);
                filestoupload.Add(filename);
                size += info.Length;
            }
        }

        using (FileForm upform = new FileForm(new List<string>(filestoupload),
                                              false, session, size, null))
        {
            upform.ExceptionMethod = ExceptionHandler;
            upform.ShowDialog();


            lsvExplorer.BeginUpdate();
            for (int i = 0; i <= upform.FilesUploaded; i++)
            {
                ListViewItem temp = new ListViewItem(new string[]{ Path.GetFileName(filestoupload[i]),
                                                                   FormatSize(new FileInfo(filestoupload[i]).Length, false)},
                                                     GetIconIndex(Path.GetExtension(filestoupload[i]), false));
                temp.Tag = false;
                lsvExplorer.Items.Add(temp);
            }
            lsvExplorer.EndUpdate();
        }
    }

我正在使用32feet和BrechamObex库。

我有以下问题:

  1. 我想将手机中的公钥发送到计算机,然后加密文件并将其发送回手机。收到文件后,我想解密它,所以我需要另一个程序来执行此操作。如何使用蓝牙将信息从一个程序发送到另一个程序?

  2. 每当我发送文件时,手机都会收到它,但它的大小总是为0

0 个答案:

没有答案