/** Deliver a packet over a given connection and get back a response */
  private JICPPacket deliver(JICPPacket pkt, Connection c) throws IOException {
    boolean lastPacket = false;
    if (Thread.currentThread() == terminator) {
      pkt.setTerminatedInfo(true);
      lastPacket = true;
    }
    pkt.setRecipientID(mediatorTA.getFile());
    byte type = pkt.getType();

    int status = 0;
    try {
      c.writePacket(pkt);
      status = 1;
      /*#MIDP_INCLUDE_BEGIN
      lock();
      if (type == JICPProtocol.RESPONSE_TYPE) {
      	TimerDispatcher.getTimerDispatcher().add(new Timer(System.currentTimeMillis()+5000, this));
      }
      #MIDP_INCLUDE_END*/
      pkt = c.readPacket();

      status = 2;
      if (lastPacket && (pkt.getInfo() & JICPProtocol.TERMINATED_INFO) != 0) {
        // When we send a packet marked with the terminated-info, the back-end may either close
        // the connection (in this case we would have got an Exception) or reply with another
        // packet marked with the terminated-info --> throws an Exception to expose a uniform
        // behaviour
        myLogger.log(Logger.INFO, "Termination notification ACK received");
        throw new IOException("Terminated-info");
      }
      return pkt;
    } catch (IOException ioe) {
      // Re-throw the exception adding the status
      throw new IOException(ioe.getMessage() + '[' + status + ']');
    } finally {
      /*#MIDP_INCLUDE_BEGIN
      if (type != JICPProtocol.RESPONSE_TYPE) {
      	// If we delivered a RESPONSE unlock() is already called by the TimerDispatcher
      	unlock();
      }
      #MIDP_INCLUDE_END*/
    }
  }