package opc.ua.communication;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class ConnectionHandler {

	private InputStream input;
	private OutputStream output;
	private TcpThread tcpThread;
	
	/**
	 * default constructor
	 * @param in
	 * @param out
	 * @param t
	 */
	public ConnectionHandler(InputStream in, OutputStream out, TcpThread t) {
		input = in;
		output = out;
		tcpThread = t;
	}

	/**
	 * process message
	 */
	/**
	 * TODO - now this function only prints what comes
	 * need to forward the message to the next layer
	 */
	public void makeTransaction() {
		byte[] b = new byte[1024];
		try {
			input.read(b);
			String mess = new String(b).trim();
			System.out.println(mess);
			if (tcpThread != null && mess.matches("exit")) {
				tcpThread.stop();
			}
		}
		catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}
	
}
