com.limegroup.gnutella.util
Class Sockets

java.lang.Object
  extended bycom.limegroup.gnutella.util.Sockets

public class Sockets
extends java.lang.Object

Provides socket operations that are not available on all platforms, like connecting with timeouts and settings the SO_KEEPALIVE option. Obsoletes the old SocketOpener class.


Method Summary
static java.net.Socket connect(java.lang.String host, int port, int timeout)
          Connects and returns a socket to the given host, with a timeout.
static boolean setKeepAlive(java.net.Socket socket, boolean on)
          Sets the SO_KEEPALIVE option on the socket, if this platform supports it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setKeepAlive

public static boolean setKeepAlive(java.net.Socket socket,
                                   boolean on)
Sets the SO_KEEPALIVE option on the socket, if this platform supports it. (Otherwise, it does nothing.)

Parameters:
socket - the socket to modify
on - the desired new value for SO_KEEPALIVE
Returns:
true if this was able to set SO_KEEPALIVE

connect

public static java.net.Socket connect(java.lang.String host,
                                      int port,
                                      int timeout)
                               throws java.io.IOException
Connects and returns a socket to the given host, with a timeout.

Parameters:
host - the address of the host to connect to
port - the port to connect to
timeout - the desired timeout for connecting, in milliseconds, or 0 for no timeout.
Returns:
the connected Socket
Throws:
java.io.IOException - the connections couldn't be made in the requested time
IllegalArgumentException - if the port is invalid