我是蓝牙开发的新手,我找到了32netfeet。现在,我可以在附近搜索蓝牙设备并连接到它们,但是如何发送文件,例如SendTest.txt?我尝试使用OBEX进行buttonclick事件,但是我不明白这是我的示例代码:
using InTheHand.Net;
using InTheHand.Net.Sockets;
using InTheHand.Net.Bluetooth;
namespace BluetoothIntheHand
{
public partial class Form2 : Form
{
private Guid service = BluetoothService.DialupNetworking;
private BluetoothClient bluetoothClient;
public Form2()
{
InitializeComponent();
}
private void btnSearch_Click(object sender, EventArgs e)
{
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio;
lblSearch.Text = "" + myRadio.LocalAddress.ToString();
bluetoothClient = new BluetoothClient();
Cursor.Current = Cursors.WaitCursor;
BluetoothDeviceInfo[] bluetoothDeviceInfo = { };
bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10);
comboBox1.DataSource = bluetoothDeviceInfo;
comboBox1.DisplayMember = "DeviceName";
comboBox1.ValueMember = "DeviceAddress";
comboBox1.Focus();
Cursor.Current = Cursors.Default;
}
private void btnConnect_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null)
{
try
{
bluetoothClient.Connect(new BluetoothEndPoint((BluetoothAddress)comboBox1.SelectedValue, service));
MessageBox.Show("Connected");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void btnSend_Click(object sender, EventArgs e)
{
bluetoothClient.Connect(new BluetoothEndPoint((BluetoothAddress)comboBox1.SelectedValue, service));
String addr = "112233445566";
Uri uri = new Uri("obex://"+@"SendTest.txt");
ObexWebRequest req= new ObexWebRequest(uri);
ObexWebResponse rsp;
}
我找到了指南,但真的不知道如何转换为C#
' The host part of the URI is the device address, e.g. IrDAAddress.ToString(),
' and the file part is the OBEX object name.
Dim addr As String = "112233445566"
Dim uri As New Uri("obex://" & addr & "/HelloWorld2.txt")
Dim req As New ObexWebRequest(uri)
Using content As Stream = req.GetRequestStream()
' Using a StreamWriter to write text to the stream...
Using wtr As New StreamWriter(content)
wtr.WriteLine("Hello World GetRequestStream")
wtr.WriteLine("Hello World GetRequestStream 2")
wtr.Flush()
' Set the Length header value
req.ContentLength = content.Length
End Using
' In this case closing the StreamWriter also closed the Stream, but ...
End Using
Dim rsp As ObexWebResponse = CType(req.GetResponse(),ObexWebResponse)
Console.WriteLine("Response Code: {0} (0x{0:X})", rsp.StatusCode)
参考方案
回答:
string fileName = @"SendTest.txt";
String adr = "0025677FB346";
Uri uri = new Uri("obex://" + adr + "/" + System.IO.Path.GetFileName(fileName));
ObexWebRequest request = new ObexWebRequest(uri);
request.ReadFile(fileName);
ObexWebResponse response = (ObexWebResponse)request.GetResponse();
MessageBox.Show(response.StatusCode.ToString());
response.Close();
当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…
改造正在返回一个空的响应主体 - java我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…
java.net.URI.create异常 - javajava.net.URI.create("http://adserver.adtech.de/adlink|3.0") 抛出java.net.URISyntaxException: Illegal character in path at index 32: http://adserver.adtech.de/adlink|3.0 虽然n…
每个文件合并后添加换行 - python我有很多类似以下内容的JSON文件:例如。1.json{"name": "one", "description": "testDescription...", "comment": ""} test.json{"name"…
Json到php,json_decode返回NULL - php我正在用PHP进行JSON解析器的一些API,用于存储有关遗产的信息。我在解析时遇到问题,因为它返回的是NULL值而不是数组或对象。简单的JSON代码可以很好地解析,但是可以这样:{"success":true,"totalCount":1,"data":[{"id":99694…