/** * Returns a reference to the underlying socket. */ public Socket getSocket() { if (socket_ == null) { initSocket(); } return socket_; }
protected TSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { Socket result = serverSocket_.accept(); TSocket result2 = new TSocket(result); result2.setTimeout(clientTimeout_); return result2; } catch (IOException iox) { throw new TTransportException(iox); } }
/** * Connects the socket, creating a new socket object if necessary. */ public void open() throws TTransportException { if (isOpen()) { throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected."); } if (host_.length() == 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open null host."); } if (port_ <= 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open without port."); } if (socket_ == null) { initSocket(); } try { socket_.connect(new InetSocketAddress(host_, port_), timeout_); inputStream_ = new BufferedInputStream(socket_.getInputStream(), 1024); outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024); } catch (IOException iox) { close(); throw new TTransportException(TTransportException.NOT_OPEN, iox); } }
private static TSocket createClient(SSLSocketFactory factory, String host, int port, int timeout) throws TTransportException { try { SSLSocket socket = (SSLSocket) factory.createSocket(host, port); socket.setSoTimeout(timeout); return new TSocket(socket); } catch (Exception e) { throw new TTransportException("Could not connect to " + host + " on port " + port, e); } }
/** * Constructor that takes an already created socket. * * @param socket Already created socket object * @throws TTransportException if there is an error setting up the streams */ public TSocket(Socket socket) throws TTransportException { socket_ = socket; try { socket_.setSoLinger(false, 0); socket_.setTcpNoDelay(true); } catch (SocketException sx) { LOGGER.warn("Could not configure socket.", sx); } if (isOpen()) { try { inputStream_ = new BufferedInputStream(socket_.getInputStream(), 1024); outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024); } catch (IOException iox) { close(); throw new TTransportException(TTransportException.NOT_OPEN, iox); } } }
protected TSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { Socket result = serverSocket_.accept(); TSocket result2 = new TSocket(result); result2.setTimeout(clientTimeout_); return result2; } catch (IOException iox) { throw new TTransportException(iox); } }
/** * Connects the socket, creating a new socket object if necessary. */ public void open() throws TTransportException { if (isOpen()) { throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected."); } if (host_.length() == 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open null host."); } if (port_ <= 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open without port."); } if (socket_ == null) { initSocket(); } try { socket_.connect(new InetSocketAddress(host_, port_), timeout_); inputStream_ = new BufferedInputStream(socket_.getInputStream(), 1024); outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024); } catch (IOException iox) { close(); throw new TTransportException(TTransportException.NOT_OPEN, iox); } }
private static TSocket createClient(SSLSocketFactory factory, String host, int port, int timeout) throws TTransportException { try { SSLSocket socket = (SSLSocket) factory.createSocket(host, port); socket.setSoTimeout(timeout); return new TSocket(socket); } catch (Exception e) { throw new TTransportException("Could not connect to " + host + " on port " + port, e); } }
/** * Constructor that takes an already created socket. * * @param socket Already created socket object * @throws TTransportException if there is an error setting up the streams */ public TSocket(Socket socket) throws TTransportException { socket_ = socket; try { socket_.setSoLinger(false, 0); socket_.setTcpNoDelay(true); } catch (SocketException sx) { LOGGER.warn("Could not configure socket.", sx); } if (isOpen()) { try { inputStream_ = new BufferedInputStream(socket_.getInputStream(), 1024); outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024); } catch (IOException iox) { close(); throw new TTransportException(TTransportException.NOT_OPEN, iox); } } }
private LCSThriftService.Client createLCSThriftClient() { TSocket socket = new TSocket( lcsAgentHostname, lcsAgentPort, 4096 * 512); TTransport transport = new TFramedTransport(socket); try { transport.open(); } catch (TTransportException e) { logger.info("Failed to create client for LCSAgent: " + lcsAgentHostname + ":" + lcsAgentPort, e); return null; } TProtocol protocol = new TCompactProtocol(transport); return new LCSThriftService.Client(protocol); } }
/** * Returns a reference to the underlying socket. */ public Socket getSocket() { if (socket_ == null) { initSocket(); } return socket_; }
/** * Creates a new unconnected socket that will connect to the given host * on the given port. * * @param host Remote host * @param port Remote port * @param timeout Socket timeout */ public TSocket(String host, int port, int timeout) { host_ = host; port_ = port; timeout_ = timeout; initSocket(); }
/** * Creates a new unconnected socket that will connect to the given host * on the given port. * * @param host Remote host * @param port Remote port * @param timeout Socket timeout */ public TSocket(String host, int port, int timeout) { host_ = host; port_ = port; timeout_ = timeout; initSocket(); }