package client;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
/**
 * Reads server input and forwards it to ByteMonitor
 * @author antonlin
 *
 */
public class InThread extends Thread {
	private Socket connection;
	private ByteMonitor monitor;

	public InThread(ByteMonitor monitor, Socket connection) {
		this.connection = connection;
		this.monitor = monitor;
		System.out.println("Inthread created.");
	}

	@Override
	public void run() {
		
		try {
			InputStream input = connection.getInputStream();
			String line = "";
			while (!connection.isClosed()) {
				int c = input.read();
				line += (char)c;
				if((char) c == '\n'|| (char) c == '\r'){
					monitor.putArrayFromServer(line.getBytes());
					System.out.println("Inthread - message received: " + line.getBytes());
					line = "";
				}
			}
			input.close();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
}

@@ -10,16 +10,47 @@
 lient;%0A%0A
+import java.io.BufferedReader;%0A
 import j
@@ -97,16 +97,50 @@
 Stream;%0A
+import java.io.InputStreamReader;%0A
 import j
@@ -603,151 +603,175 @@
 %0A%09%09%09
-String line = %22%22;%0A%09%09%09while (!connection.isClosed()) %7B%0A%09%09%09%09int c = input.read();%0A%09%09%09%09line += (char)c;%0A%09%09%09%09if((char) c == '%5Cn'%7C%7C (char) c == '%5Cr'
+BufferedReader br = new BufferedReader(new InputStreamReader(input));%0A%09%09%09String line = %22%22;%0A%09%09%09while (!connection.isClosed()) %7B%0A%09%09%09%09while((line = br.readLine()) != null
 )%7B%0A%09
@@ -899,24 +899,8 @@
 ));%0A
-%09%09%09%09%09line = %22%22;%0A
 %09%09%09%09

change to bufferedreader