@Override
	protected void handleMessage(Object o) throws Exception {
		try {
//			stopHeartBeat();
			if( ! isOpen()) {
				
				if(o instanceof Message) {
					Message m = (Message) o;
					m.setMessageSent(false);
				} else if(o instanceof CloseConfirmationRequest) {
					CloseConfirmationRequest req = (CloseConfirmationRequest) o;
					req.getAccessor().confirmClose(false);
				}
				return;

			}
			
			if(o instanceof CloseConfirmationRequest) {

				CloseConfirmationRequest req = (CloseConfirmationRequest) o;
				req.getAccessor().confirmClose(true);

			} else if(o instanceof Message) {

				Message m = (Message) o;
				m.setSender(thisDaId);
				m.setRecipient(remoteDaId);

				assert seqNum-1 == lastSent;
				lastSent = seqNum;
				m.setSeqNum(seqNum++);
				
				
				agentPrintMessage("Sending message n°"+m.getSeqNum()+
						" ("+o.getClass().getSimpleName()+")");

				try {

					sendMessage(m);
					m.setMessageSent(true);
//					startHeartBeat();

				} catch (NotSerializableException e) {

					throw e;

				} catch (IOException e) {

					signalBrokenStream(e);
					m.setMessageSent(false);

				} catch (OutOfSyncException e) {

					signalBrokenStream(e);
					m.setMessageSent(false);

				}

			} else {

				throw new UnknownAgentMessage(o);

			}
		} catch (Exception e) {
			synchronized (this) {
				state = State.closed;
			}
			
			throw e;
		}
		
	}