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 { final ClientSocketFactory clientSocketFactory = getClientSocketFactory(); if (protocol == Protocol.UDP) { out = new UdpOutputStream(clientSocketFactory); } else { out = new TcpOutputStream(clientSocketFactory, blockOnReconnect); } setOutputStream(out, false); } catch (IOException e) { throw new IllegalStateException("Could not set " + protocol + " output stream.", e); } } }
private OutputStream createOutputStream() { if (address != null || port >= 0) { try { final ClientSocketFactory socketFactory = getClientSocketFactory(); if (protocol == Protocol.UDP) { return new UdpOutputStream(socketFactory); } return new TcpOutputStream(socketFactory, blockOnReconnect); } catch (IOException e) { reportError("Failed to create socket output stream", e, ErrorManager.OPEN_FAILURE); } } return null; }