package com.github.noxan.aves.client;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

import com.github.noxan.aves.net.Connection;

public class SocketClient implements Client, Connection {
    private String host;
    private int port;
    private Socket socket;
    private ClientHandler handler;

    public SocketClient(ClientHandler handler) {
        this("localhost", 1666, handler);
    }

    public SocketClient(String host, int port, ClientHandler handler) {
        this.host = host;
        this.port = port;
        this.handler = handler;
    }

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

    @Override
    public String getHost() {
        return host;
    }

    @Override
    public int getPort() {
        return port;
    }

    @Override
    public void connect() throws IOException {
        handler.clientConnect();
        socket = new Socket();
        socket.connect(new InetSocketAddress(host, port));
    }

    @Override
    public void disconnect() {
        handler.clientDisconnect();
    }
}

@@ -164,16 +164,246 @@
 nection;
+%0Aimport com.github.noxan.aves.protocol.InputProtocol;%0Aimport com.github.noxan.aves.protocol.OutputProtocol;%0Aimport com.github.noxan.aves.protocol.ProtocolFactory;%0Aimport com.github.noxan.aves.protocol.string.StringProtocolFactory;
 %0A%0Apublic
@@ -564,16 +564,116 @@
 ndler;%0A%0A
+    private ProtocolFactory factory;%0A    private InputProtocol in;%0A    private OutputProtocol out;%0A%0A
     publ
@@ -752,16 +752,45 @@
  handler
+, new StringProtocolFactory()
 );%0A    %7D
@@ -851,32 +851,57 @@
 tHandler handler
+, ProtocolFactory factory
 ) %7B%0A        this
@@ -972,16 +972,48 @@
 andler;%0A
+        this.factory = factory;%0A
     %7D%0A%0A 
@@ -1409,24 +1409,161 @@
 st, port));%0A
+        in = factory.createInputProtocol(socket.getInputStream());%0A        out = factory.createOutputProtocol(socket.getOutputStream());%0A
     %7D%0A%0A    @

add protocols with factory to socketclient and initial on connect