java - Android Bluetooth sending file problem -
i writing small program send file between android , pc through bluetooth. read bluetooth chat example in google android site.
currently, version works sending text message via bluetooth, when send files, around >= 20 kb, stops working , throwing eofexception below:
java.io.eofexception @ java.io.objectinputstream$blockdatainputstream.readfully(objectinputstream.java:2716) @ java.io.objectinputstream.readarray(objectinputstream.java:1665) @ java.io.objectinputstream.readobject0(objectinputstream.java:1340) @ java.io.objectinputstream.defaultreadfields(objectinputstream.java:1963) @ java.io.objectinputstream.readserialdata(objectinputstream.java:1887) @ java.io.objectinputstream.readordinaryobject(objectinputstream.java:1770) @ java.io.objectinputstream.readobject0(objectinputstream.java:1346) @ java.io.objectinputstream.readobject(objectinputstream.java:368) @ com.test.pcserver.bluetoothserverlistener.run(bluetoothserverlistener.java:74) @ java.lang.thread.run(thread.java:636)
currently, java program on pc using bluecove-2.1.0
here main codes:
in android:
// bluetoothdevice object if (bluetoothadapter.checkbluetoothaddress(address)) { device = mbtadapter.getremotedevice(address); // bluetoothsocket connection // given bluetoothdevice socket = device .createrfcommsockettoservicerecord(programconstants.bluetooth_uuid); socket.connect(); out = new objectoutputstream(socket.getoutputstream()); // send pc out.writeobject(contentobject); out.flush(); }
in pc, read it:
pc version, server
streamconnectionnotifier streamconnnotifier = null; // create service url string connectionstring = "btspp://localhost:" + programconstants.bluetooth_uuid.tostring() + ";name=myappname"; // open server url streamconnnotifier = (streamconnectionnotifier) connector.open(connectionstring); while (true) { // wait client connection streamconnection connection = streamconnnotifier.acceptandopen(); objectinputstream in = new objectinputstream(connection.openinputstream()); remotedevice dev = remotedevice.getremotedevice(connection); // read string spp client dataincontroller data = new dataincontroller(model); data.processdatain(in.readobject(), dev.getbluetoothaddress()); }
you need add after flushing outputstream
out.close();
otherwise stream can become corrupted.
Comments
Post a Comment