1
我已经关注了一篇关于创建一个可以找到蓝牙设备的应用程序的博客文章,并且通过选择一个文件,我们可以将其上传到手机。插座操作试图通过蓝牙无法访问网络
网文章链接: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来找出服务器套接字是否在该端口监听 – TheWhiteRabbit
同样@TechExchange说的也是常用的:防火墙?同一子网?代理? –
哪个端口用于蓝牙? –