1

I've followed a blog article about making an application which finds Bluetooth devices and by selecting a file we can upload it to phone.

web article link: 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();
    }

Now when running app, I can see list of devices available and I can select a device and also select a file for upload but when I click send it throws an error and it's content is:

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) 
j0k
  • 22,600
  • 28
  • 79
  • 90
scn scn
  • 43
  • 2
  • 4

1 Answers1

1

I have faced with the same issue on Windows 7, 64 bit and after I removed device from the list of Bluetooth Devices and then paired it again the problem was gone.

Alex K
  • 525
  • 5
  • 6