private void init() {
        if (initializeConnection && !outputStreamSet) {
            if (serverAddress == null || port < 0 || protocol == null) {
                throw new IllegalStateException("Invalid connection parameters. The port, server address and protocol must be set.");
            }
            initializeConnection = false;
            final OutputStream out;
            // Check the sockets
            try {
                if (protocol == Protocol.TCP) {
                    out = new TcpOutputStream(serverAddress, port, blockOnReconnect);
                } else if (protocol == Protocol.UDP) {
                    out = new UdpOutputStream(serverAddress, port);
                } else if (protocol == Protocol.SSL_TCP) {
                    out = new SslTcpOutputStream(serverAddress, port, blockOnReconnect);
                } else {
                    throw new IllegalStateException("Invalid protocol: " + protocol);
                }
                setOutputStream(out, false);
            } catch (IOException e) {
                throw new IllegalStateException("Could not set " + protocol + " output stream.", e);
            }
        }
    }