【发布时间】:2013-01-15 13:19:58
【问题描述】:
我关注了一篇博客文章,该文章介绍了如何创建一个应用程序来查找蓝牙设备并通过选择一个文件将其上传到手机。
网络文章链接:http://www.substanceofcode.com/2008/06/20/sending-files-to-mobile-phone-using-bluetooth-and-obex/
private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_uploadButtonActionPerformed
try {
// Get selected item from list
ListItem selectedItem = (ListItem) deviceList.getSelectedValue();
RemoteDevice device = selectedItem.getDevice();
// Build URL for the bluetooth device, note the port 9
String url = "btgoep://" + device.getBluetoothAddress() + ":9";
// Get file as bytes
FileInputStream stream = new FileInputStream(fileTextField.getText());
File f = new File(fileTextField.getText());
int size = (int) f.length();
byte[] file = new byte[size];
stream.read(file);
// Filename
String filename = f.getName();
// Trigger the task in a different thread so it won't block the UI
SendFileTask task = new SendFileTask(url, file, filename);
Thread thread = new Thread(task);
task.run();
} catch(Exception ex) {
System.err.println("Ex: " + ex.getMessage());
ex.printStackTrace();
}
现在在运行应用程序时,我可以看到可用设备列表,我可以选择设备并选择要上传的文件,但是当我单击发送时会引发错误,其内容是:
A socket operation was attempted to an unreachable network.
javax.bluetooth.BluetoothConnectionException: Failed to connect; [10051] A socket operation was attempted to an unreachable network.
at com.intel.bluetooth.BluetoothStackMicrosoft.connect(Native Method)
at com.intel.bluetooth.BluetoothStackMicrosoft.access$700(BluetoothStackMicrosoft.java:44)
at com.intel.bluetooth.BluetoothStackMicrosoft$ConnectThread.run(BluetoothStackMicrosoft.java:651)
【问题讨论】:
-
运行 netstat 以确定服务器套接字是否在该端口监听
-
同上@TechExchange 所说的,以及通常的做法:防火墙?同一个子网?代理?
-
哪个端口用于蓝牙?