public <T> T connect(Class<T> serviceInterface) throws IOException {
        if (!serviceInterface.isInterface()) {
            throw new IllegalArgumentException("serviceInterface must be of interface type!");
        }
        try {
            socket = new Socket(this.serverHost, this.serverPort);
            outputStream = socket.getOutputStream();
            inputStream = socket.getInputStream();
        } catch (IOException e) {
            if (inputStream != null) {inputStream.close();}
            if (outputStream != null) {outputStream.close();}
            if (socket != null) {socket.close();}

            throw e;
        }
        return (T) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{serviceInterface}, this);
    }