I want to share an object of type Stuff that contains (line name, address, name, ... and byte [] image), when the connection is established after this, my code hangs in the objectinputstream readObject () function. No streaming occurs. Can someone please find out where I am doing wrong.
private class ConnectedThread extends Thread { private final BluetoothSocket mmSocket; private final InputStream mmInStream; private final OutputStream mmOutStream; private ObjectOutputStream oos = null; private ObjectInputStream ois = null; public ConnectedThread(BluetoothSocket socket) { Log.d(TAG, "create ConnectedThread"); mmSocket = socket; Log.d(TAG, "create a"); InputStream tmpIn = null; Log.d(TAG, "create b"); OutputStream tmpOut = null;
My code hangs at this point, never move forward.
`// Keep listening to the InputStream while connected while (true) { try { Log.d("Connected thread run ", "start while"); try { Stuff obj_rcv = (Stuff) ois.readObject(); Log.d("BTS", "rcv object " + obj_rcv.getName()); Message msg2 = mHandler .obtainMessage(RemoteBusinessCard.MESSAGE_READ); Bundle bundle = new Bundle(); bundle.putSerializable("person", obj_rcv); msg2.setData(bundle); mHandler.sendMessage(msg2); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } catch (IOException e) { Log.e(TAG, "disconnected", e); connectionLost(); break; } } } /** * Write to the connected OutStream. * * @param buffer * The bytes to write */ public void write(Stuff object) { try { Log.d("BTS", "inside write before" + object.getName()); oos.writeObject(object); Log.d("BTS", "inside write after" + object.getName()); oos.flush(); oos.close(); } catch (IOException e) { Log.e(TAG, "Exception during write", e); } } public void cancel() { try { mmSocket.close(); } catch (IOException e) { Log.e(TAG, "close() of connect socket failed", e); } } }`
Ahmed source share