C# 蓝牙传输
我正在尝试制作一个程序,将文件发送到一个加密的移动设备,该设备将在另一个程序中获取并解密它 到目前为止,我已经完成了蓝牙连接:C# 蓝牙传输,c#,wpf,bluetooth,32feet,obex,C#,Wpf,Bluetooth,32feet,Obex,我正在尝试制作一个程序,将文件发送到一个加密的移动设备,该设备将在另一个程序中获取并解密它 到目前为止,我已经完成了蓝牙连接: private void Connect() { using (SelectBluetoothDeviceDialog bldialog = new SelectBluetoothDeviceDialog()) { bldialog.ShowAuthenticated = true; bldialog.ShowRememb
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();
}
}
private void上传文件(字符串[]文件)
{
长尺寸=0;
List filestoupload=new List();
foreach(文件中的字符串文件名)
{
if(File.Exists(filename))
{
FileInfo=newfileinfo(文件名);
filestoupload.Add(文件名);
大小+=信息长度;
}
}
使用(FileForm upform=newfileform(new List(filestoupload)),
false,会话,大小,空)
{
upform.ExceptionMethod=ExceptionHandler;
upform.ShowDialog();
lsvExplorer.BeginUpdate();
对于(int i=0;我不完全理解你的1.问题。你想先保存你的文件,然后让另一个程序对它们进行加密,然后再发送吗?对不起,我一时想不起来了。edit为什么不使用类似的var buffer=System.Text.Encoding.UTF8.GetBytes(“你想发送的任何东西”)呢;var stream=client.GetStream();stream.Write(buffer,0,buffer.Length);stream.Flush();stream.Close();
要发送内容吗?