无法使用32feet.Net C#库通过蓝牙将文件从Windows传输到Linux

时间:2012-06-12 14:02:55

标签: c# windows linux bluetooth

使用以下命令启动第一个linux服务侦听进程:

obexpushd -B [00:15:83:3D:0A:57]:9 -d -o / home / myfolder

在Windows上,以下代码用于执行obex传输:

InTheHand.Net.BluetoothAddress address = peerDevice.DeviceAddress;
   System.Uri uri = new Uri("obex://" + address.ToString() + "/" + srcfile.Name);
   request = new ObexWebRequest(uri);
   startcopy = DateTime.Now;

   request.ReadFile(file); // this performs the file read from the hard drive

   try
   {
       response = (ObexWebResponse)request.GetResponse(); // here file should be pushed to the listening service
   }
   catch (System.InvalidOperationException ex)
   {
       if (response != null) {
                            response.Close();
       }
       return;
   }

设备互相看见,他们的obex服务也可见。 转移似乎是成功的,但实际上没有数据传输。 代码在窗口和窗口之间工作没有问题。

Obexpushd流程输出显示:

obexpushd 0.10.2 Copyright (C) 2006-2010 Hendrik Sattler
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
Listening on bluetooth/[00:15:83:3D:0A:57]:9
OBEX_EV_ACCEPTHINT, OBEX_CMD_CONNECT
0: Connection from "bluetooth/[00:09:DD:50:94:0B]:9"
0: OBEX_EV_REQHINT, OBEX_CMD_CONNECT
0: OBEX_EV_REQ, OBEX_CMD_CONNECT
0: Sending response code 0
0: OBEX_EV_REQDONE, OBEX_CMD_CONNECT
0: OBEX_EV_REQHINT, OBEX_CMD_PUT
0.1: OBEX_EV_REQCHECK, OBEX_CMD_PUT
0.1: OBEX_EV_REQDONE, OBEX_CMD_PUT
0.1: OBEX_EV_REQHINT, OBEX_CMD_DISCONNECT
0.1: Sending response code 100
0.1: OBEX_EV_REQ, OBEX_CMD_DISCONNECT
0.1: OBEX_EV_REQDONE, OBEX_CMD_DISCONNECT

我还尝试在C#代码中禁用身份验证,但这没有帮助。

是否有人知道如何解决这个问题或者甚至在哪里开始寻找?

1 个答案:

答案 0 :(得分:1)

好的,似乎没有人对这个话题感兴趣。 :)幸运的是我自己找到了解决方案。

然而,它涉及大量分析(obex传输协议和32feet库)和一点运气。 Linux obexpushd 实现之间的区别在于它对OBEX传输数据包的解释。

我在页面上找到了OBEX规范:OBEX specification

在调试23feet obex传输的内部后,我发现代码发送OBEX PUT命令的位置,用于将文件发送到接收器。 Obex规范为PUT初始化数据包提供了以下示例:

PUT命令|包的长度|名称标题| Name头的长度|对象名称|长度标题|物体长度| Object Body块头| Body头的长度|身体的字节

32feet库发送第一个数据包没有 Body Header ,这会导致 obexpushd Linux命令出错。

如果32feet库中出现错误,obexpushd或者OBEX规范不够精确,但是将Body标头添加到第一个数据包解决了问题,那么它不是真的。根据我的实验,事实证明必须在第一个数据包中发送至少2个对象的第一个字节。此外,添加标题不会导致任何其他问题,Windows< - > Windows传输仍然可以正常运行。