package protocol;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import net.TCPClient;

public class TCPClientMessage extends TCPClient implements MessageConnection {

	private ObjectInputStream in;
	private ObjectOutputStream out;

	@Override
	public void connect () throws IOException {
		super.connect();
		out = new ObjectOutputStream(sock.getOutputStream());
		in = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));	
	}

	public Message getMessage() throws IOException {
			try {
				return (Message) in.readObject();
			}  catch (ClassNotFoundException e) {
				throw new IOException("Protocol Message layer error :"+e);
			}	
	}

	public void sendMessage(Message m) throws IOException {
		out.writeObject(m);
	}



	
}
