@Override
	public void run() {
		log("Connection accepted");

		InputStream in;
		OutputStream out;
		IObjectChannel channel;
		try {
			in = client.getInputStream();
			out = client.getOutputStream();
			channel = channelFactory.create(out, in);
			channel.setLogAdapter(this);
		} catch (IOException e1) {
			throw new RuntimeException(e1);
		}

		try {
			Object inputObject;
			Object outputObject;  
			try {
				while ((inputObject = channel.readObject()) != null) {
					// Process input
					outputObject = handler.process(inputObject);
					channel.writeObject(outputObject);
					// check whether to continue or not
					if (isClosed() || client.isClosed() || handler.breakConnection()) break;
				}
				log("Connection closed");
			} catch (ClassNotFoundException e) {
				outputObject = handler.getIllegalRequestResponse();
				channel.writeObject(outputObject);
				log(e.toString());
				log("Connection closed");
			} finally {
				out.close();
				in.close();
			}
		} catch (EOFException e) {
			log("Connection closed by client");
		} catch (IOException e2) {
			log(e2.getMessage());
			log("Connection closed");
		} finally {
			close();
		}
	}