@Override
	public ElapsedTimeInterval ping(String header, String hostIP, int port, int timeout, int nTrials) throws Exception {
		
		//TODO: implement this method
		
		try {

			Socket tcpSocket = null;
			TCPMessageHandler tcpMessageHandlerSocket = null;
			String msg = "";
			for(int i = 0 ; i < nTrials ; i++) {
				try {
					ElapsedTime.start("PingTCPMessageHandler_PingTotalDelay");
					
					// set up the Message Handler
					tcpSocket = new Socket(hostIP, port);
					tcpMessageHandlerSocket = new TCPMessageHandler(tcpSocket);
					tcpMessageHandlerSocket.setTimeout(timeout);
					tcpMessageHandlerSocket.setNoDelay(true);
					
					// send the header and message
					tcpMessageHandlerSocket.sendMessage(header);
					tcpMessageHandlerSocket.sendMessage(msg);

					// read response header
					String headerStr = tcpMessageHandlerSocket.readMessageAsString();
					if ( ! headerStr.equalsIgnoreCase(EchoServiceBase.RESPONSE_OKAY_STR) )
						throw new Exception("Bad response header: '" + headerStr + "'");

					// read response payload (which should be empty)
					String response = tcpMessageHandlerSocket.readMessageAsString();
					if ( !  response.equals(msg))
						throw new Exception("Bad response payload: sent '" + msg + "' got back '" + response + "'");
				} catch (SocketTimeoutException e) {
					System.out.println("Timed out");
					ElapsedTime.abort("PingTCPMessageHandler_PingTotalDelay");
				} catch (Exception e) {
					System.out.println("TCPMessageHandler read failed: " + e.getMessage());
					ElapsedTime.abort("PingTCPMessageHandler_PingTotalDelay");
				} finally {
					if ( tcpMessageHandlerSocket != null ) {
						try {
							tcpMessageHandlerSocket.close();
							ElapsedTime.stop("PingTCPMessageHandler_PingTotalDelay");
						} catch (Exception e) {
							ElapsedTime.abort("PingTCPMessageHandler_PingTotalDelay");
						}
					}
				}
			}
		} catch (Exception e) {
			System.out.println("Exception: " + e.getMessage());
			ElapsedTime.abort("PingTCPMessageHandler_PingTotalDelay");
		}

		return ElapsedTime.get("PingTCPMessageHandler_PingTotalDelay");
	}