public void sendMessage(Message message) throws NotYetConnectedException {
  lock.lock();
  try {
    if (writeTarget == null)     throw new NotYetConnectedException();
  }
  finally {
    lock.unlock();
  }
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  try {
    serializer.serialize(message,out);
    writeTarget.writeBytes(out.toByteArray());
  }
 catch (  IOException e) {
    exceptionCaught(e);
  }
}

public void sendMessage ( Message message ) throws NotYetConnectedException { lock . lock ( ) ; try { if ( writeTarget == null ) throw new NotYetConnectedException ( ) ; } finally { lock . unlock ( ) ; } ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; try { serializer . serialize ( message , out ) ; writeTarget . writeBytes ( out . toByteArray ( ) ) ; } catch ( IOException e ) { exceptionCaught ( e ) ; } }
sends the given message to the peer . due to the asynchronousness of network programming , there is no guarantee the peer will have received it . throws notyetconnectedexception if we are not yet connected to the remote peer . todo : maybe use something other than the unchecked notyetconnectedexception here
