Socket setSoTimeout - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Socket setSoTimeout method.

This code example shows how to use the following methods:setSoTimeout
   * @param timeout Milliseconds timeout 
   */ 
  public void setTimeout(int timeout) {
    this.timeout = timeout;
    try { 
      socket.setSoTimeout(timeout);
    } catch (SocketException sx) {
      LOGGER.warn("Could not set socket timeout.", sx);
    } 
  } 
 
  /** 
   * Returns a reference to the underlying socket. 
   */ 
  public Socket getSocket() {
    if (socket == null) {
      initSocket(); 
    } 
    return socket;
  } 
8
CodeRank
This code example shows how to use the following methods:close, connect, setReuseAddress, setSoLinger, setSoTimeout
      InetSocketAddress socketAddress = new InetSocketAddress(socketA.getHostText(), socketA
               .getPort());
      Socket socket = null;
      try { 
         logger.trace("testing socket %s", socketAddress);
         socket = new Socket(
               proxyForURI.apply(URI.create("socket://" + socketA.getHostText() + ":" + socketA.getPort())));
         socket.setReuseAddress(false);
         socket.setSoLinger(false, 1);
         socket.setSoTimeout(timeout);
         socket.connect(socketAddress, timeout);
      } catch (IOException e) {
         return false; 
      } finally { 
         if (socket != null) {
            try { 
               socket.close();
            } catch (IOException ioe) {
               // no work to do 
            } 

8
CodeRank
This code example shows how to use the following methods:setSoTimeout
   */ 
  public void setTimeout(long timeoutMs) throws SocketException {
    if (hasChannel) {
      ((SocketInputStream)in).setTimeout(timeoutMs);
    } else { 
      socket.setSoTimeout((int)timeoutMs);
    } 
  } 
 
  /** 
   * @return an underlying ReadableByteChannel implementation. 
   * @throws IllegalStateException if this socket does not have a channel 
   */ 
  public ReadableByteChannel getReadableByteChannel() {
    Preconditions.checkState(hasChannel,
        "Socket %s does not have a channel", 
        this.socket);
    return (SocketInputStream)in;
  } 
} 
8
CodeRank
This code example shows how to use the following methods:setSoTimeout
    return null; 
  } 
 
  @Override 
  public void setReadTimeout(int timeoutMs) throws IOException {
    socket.setSoTimeout(timeoutMs);
  } 
 
  @Override 
  public int getReceiveBufferSize() throws IOException { 
    return socket.getReceiveBufferSize();
  } 
 
  @Override 
  public boolean getTcpNoDelay() throws IOException { 
    return socket.getTcpNoDelay();
  } 
 
  @Override 
  public void setWriteTimeout(int timeoutMs) {
8
CodeRank
This code example shows how to use the following methods:connect, getOutputStream, setKeepAlive, setSoTimeout
    extends BaseKeyedPooledObjectFactory<SocketConnectionInfos, SocketOutputStream>  
    implements KeyedPooledObjectFactory<SocketConnectionInfos, SocketOutputStream> { 
 
    private final int socketTimeoutInMillis;
    private final int socketConnectTimeoutInMillis;
 
    public SocketOutputStreamPoolFactory(int socketConnectTimeoutInMillis, int socketTimeoutInMillis) {
        this.socketConnectTimeoutInMillis = socketConnectTimeoutInMillis;
        this.socketTimeoutInMillis = socketTimeoutInMillis;
    } 
 
    @Override 
    public PooledObject<SocketOutputStream> makeObject(SocketConnectionInfos connectionInfos) throws Exception {
        return wrap(create(connectionInfos));
    } 
 
    @Override 
    public void destroyObject(SocketConnectionInfos socketConnectionInfos, PooledObject<SocketOutputStream> socketOutputStream) throws Exception {
        super.destroyObject(socketConnectionInfos, socketOutputStream);
        SocketOutputStream outputStream = socketOutputStream.getObject();

7
CodeRank
This code example shows how to use the following methods:getChannel, setSoTimeout
    if (withChannel) {
      s = NetUtils.getDefaultSocketFactory(new Configuration())
          .createSocket(); 
      Assume.assumeNotNull(s.getChannel());
    } else { 
      s = new Socket();
      assertNull(s.getChannel());
    } 
     
    SocketInputWrapper stm = null;
    try { 
      NetUtils.connect(s, ss.getLocalSocketAddress(), 1000);
 
      stm = NetUtils.getInputStream(s, 1000);
      assertReadTimeout(stm, 1000);
 
      // Change timeout, make sure it applies. 
      stm.setTimeout(1);
      assertReadTimeout(stm, 1);
       

7
CodeRank
This code example shows how to use the following methods:connect, getInputStream, getOutputStream, setSoTimeout
 
    public void connect(int connectTimeout, int soTimeout)
           throws UnknownHostException, IOException {
        final String encoding = "ISO-8859-1";
        SocketAddress addr = new InetSocketAddress("localhost", port);
        socket = new Socket();
        socket.setSoTimeout(soTimeout);
        socket.connect(addr,connectTimeout);
        OutputStream os = socket.getOutputStream();
        writer = new OutputStreamWriter(os, encoding);
        InputStream is = socket.getInputStream();
        Reader r = new InputStreamReader(is, encoding);
        reader = new BufferedReader(r);
    } 
    public void connect() throws UnknownHostException, IOException {
        connect(0,0); 
    } 
 
    public void processRequest() throws IOException, InterruptedException {
        processRequest(true); 
7
CodeRank
This code example shows how to use the following methods:setKeepAlive, setSoTimeout
        } 
    } 
 
    public void rollbackTimeout() { 
        try { 
            socket.setSoTimeout(timeout);
            socket.setKeepAlive(false);
        } catch (SocketException ex) {
            throw new JedisException(ex);
        } 
    } 
 
    public Connection(final String host) {
        super(); 
        this.host = host;
    } 
 
    protected void flush() { 
        try { 
            outputStream.flush();
7
CodeRank
This code example shows how to use the following methods:setSoTimeout
        this.socket = socket;
    } 
 
    public void setTimeout(int timeoutMilliseconds) {
        try { 
            socket.setSoTimeout(timeoutMilliseconds);
        } catch (SocketException e) {
            logger.error("Failed to set timeout", e);
        } 
    } 
 
    public Object readObject() { 
 
        ObjectInputStream reader = null;
 
        try { 
            reader = new ObjectInputStream(socket.getInputStream());
        } catch (SocketException e) {
            if (!isIgnorableException(e)) {
                logger.error("Reading Object", e);
6
CodeRank
This code example shows how to use the following methods:connect, setSoLinger, setSoTimeout
	}	 
	 
	@Override 
	public Socket createSocket(String host, int port) throws IOException {
 
		Socket socket = new Socket();
		socket.setSoTimeout(readTimeout);
		socket.setSoLinger(false, 0);
		socket.connect(new InetSocketAddress(host, port), connectionTimeout);
		return socket;
	} 
 
	@Override 
	public ServerSocket createServerSocket(int port) throws IOException {
 
		return new ServerSocket(port);
	} 
} 
7
CodeRank

Related Socket setSoTimeout Questions & Answers:

setSoTimeout Method Overview
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
See Code Examples for other Java 8 Socket Methods: