package com.github.noxan.aves.net;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.github.noxan.aves.protocol.string.StringInputProtocol;
import com.github.noxan.aves.protocol.string.StringOutputProtocol;
import com.github.noxan.aves.server.Server;

public class SocketConnection implements Connection {
    private Logger logger = Logger.getLogger(SocketConnection.class.getName());

    private Server server;
    private Socket socket;

    private StringInputProtocol in;
    private StringOutputProtocol out;

    private boolean isConnected;

    public SocketConnection(Server server, Socket socket) {
	this.server = server;
	this.socket = socket;
	try {
	    in = new StringInputProtocol(socket.getInputStream());
	    out = new StringOutputProtocol(socket.getOutputStream());
	} catch (IOException e) {
	    e.printStackTrace();
	}
    }

    @Override
    public void write(Object data) throws IOException {
	out.write(data);
    }

    @Override
    public void start() {
	logger.log(Level.INFO, "connection connected");
	isConnected = true;
    }

    @Override
    public InetAddress getHost() {
	return socket.getInetAddress();
    }

    @Override
    public int getPort() {
	return socket.getPort();
    }
}

@@ -29,16 +29,45 @@
 s.net;%0A%0A
+import java.io.EOFException;%0A
 import j
@@ -1354,11 +1354,626 @@
 );%0A    %7D
+%0A%0A    private class InputManager implements Runnable %7B%0A%09@Override%0A%09public void run() %7B%0A%09    while (isConnected) %7B%0A%09%09try %7B%0A%09%09    Object data = in.read();%0A%09%09    if (data != null) %7B%0A%09%09%09logger.log(Level.INFO, %22data: %22+data);%0A%09%09    %7D else %7B%0A%09%09%09isConnected = false;%0A%09%09%09logger.log(Level.INFO, %22connection disconnected%22);%0A%09%09    %7D%0A%09%09%7D catch (EOFException e) %7B%0A%09%09    e.printStackTrace();%0A%09%09    logger.log(Level.INFO, %22connection dropped%22);%0A%09%09    isConnected = false;%0A%09%09%7D catch (IOException e) %7B%0A%09%09    e.printStackTrace();%0A%09%09    logger.log(Level.INFO, %22connection disconnected%22);%0A%09%09    isConnected = false;%0A%09%09%7D%0A%09    %7D%0A%09%7D%0A    %7D
 %0A%7D%0A

implement inputmanager in socketconnection to read stringinputprotocol and output to logger