/** * Create, configure and connect a socket. * @param address The address to connect to * @param options The socket options to configure. If null, no socket options will be configured * @return The configured and connected socket * @throws IOException */ public static Socket createAndConnect(SocketAddress address, SocketOptionsConfig options) throws IOException { final Socket result = new Socket(); configureSocketOptions(result, options); logger.debug("Connecting socket"); if (options != null && options.hasConnectTimeout()) { result.connect(address, options.getConnectTimeout()); } else { result.connect(address); } logger.debug("Socket connected"); return result; }
/** * Create, configure and connect a socket. * @param address The address to connect to * @param options The socket options to configure. If null, no socket options will be configured * @return The configured and connected socket * @throws IOException */ public static Socket createAndConnect(SocketAddress address, SocketOptionsConfig options) throws IOException { final Socket result = new Socket(); configureSocketOptions(result, options); logger.debug("Connecting socket"); if (options != null && options.hasConnectTimeout()) { result.connect(address, options.getConnectTimeout()); } else { result.connect(address); } logger.debug("Socket connected"); return result; }
@Override public String toString() { final StringBuilder msg = new StringBuilder(getClass().getSimpleName()).append("["); if (hasConnectTimeout()) { msg.append("connect timeout = ").append(getSoTimeout()).append(" ms "); } if (hasSoTimeout()) { msg.append("socket timeout = ").append(getSoTimeout()).append(" ms "); } if (hasSndBuffSize()) { msg.append("send buffer size = ").append(getSndBuffSize()).append(" "); } if (hasRcvBuffSize()) { msg.append("receive buffer size = ").append(getRcvBuffSize()).append(" "); } msg.append("keep alive = ").append(isKeepAlive()).append("]"); return msg.toString(); }
@Override public String toString() { final StringBuilder msg = new StringBuilder(getClass().getSimpleName()).append("["); if (hasConnectTimeout()) { msg.append("connect timeout = ").append(getSoTimeout()).append(" ms "); } if (hasSoTimeout()) { msg.append("socket timeout = ").append(getSoTimeout()).append(" ms "); } if (hasSndBuffSize()) { msg.append("send buffer size = ").append(getSndBuffSize()).append(" "); } if (hasRcvBuffSize()) { msg.append("receive buffer size = ").append(getRcvBuffSize()).append(" "); } msg.append("keep alive = ").append(isKeepAlive()).append("]"); return msg.toString(); }