IOException: broken pipe when sending file from android device to PC via Bluetooth

774 views Asked by At

I'm working on a project where I try to send any file from my phone to my PC. I made the following steps and they all work well:

  1. Find out available device to connect
  2. Pairing the Bluetooth device
  3. Connecting to PC using BluetoothSocket.

The problem happens when I try to write byte[] to PC using BluetoothOutputStream.

InputStream fis = null;
    OutputStream os = null;
        if (isConnected && toSend != null) {
            try {
                fis = new FileInputStream(toSend);
                os = socket.getOutputStream();
                byte[] buf = new byte[2048];
                if(socket.isConnected()){
                    while ((fis.read(buf)) != -1) {
                        os.write(buf);
                    }
                    os.flush();
                    Log.i("tag", "write complete");
                }
                Log.i("tag", "socket is not yet connected");
            } catch (IOException e) {
                e.printStackTrace();
            } 

When it gets to os.write(), a

ioexcoption: broken pipe

is shown in eclipse logcat and I receive nothing on my PC.

Does anyone know how to handle this problem? I figure that my PC is the cause.

0

There are 0 answers