Code example for Socket

Methods: closeconnectgetChannelgetInetAddressgetLocalAddressgetLocalPortgetPort

   * @see Socket#getChannel() 
   * @param socket 
   * @param timeout timeout in milliseconds. This may not always apply. zero 
   *        for waiting as long as necessary. 
   * @return OutputStream for writing to the socket. 
   * @throws IOException    
  public static OutputStream getOutputStream(Socket socket, long timeout) 
                                             throws IOException { 
    return (socket.getChannel() == null) ? 
            socket.getOutputStream() : new SocketOutputStream(socket, timeout);            
   * This is a drop-in replacement for  
   * {@link Socket#connect(SocketAddress, int)}. 
   * In the case of normal sockets that don't have associated channels, this  
   * just invokes <code>socket.connect(endpoint, timeout)</code>. If  
   * <code>socket.getChannel()</code> returns a non-null channel, 
   * connect is implemented using Hadoop's selectors. This is done mainly 
   * to avoid Sun's connect implementation from creating thread-local  
   * selectors, since Hadoop does not have control on when these are closed 
   * and could end up taking all the available file descriptors. 
   * @see, int) 
   * @param socket 
   * @param endpoint  
Experience pair programming with AI  Get Codota for Java