Package fr.dyade.aaa.common.net
Class SocketFactory
- java.lang.Object
-
- fr.dyade.aaa.common.net.SocketFactory
-
- Direct Known Subclasses:
SocketFactory13,SocketFactory14
public abstract class SocketFactory extends Object
This class wraps multiples implementations of the java.net.Socket class.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDefaultFactoryThe default implementation of the SocketFactory interface is for JDK since 1.4.private static SocketFactoryfactoryprivate static String[]factoryClasses(package private) static Loggerlogger
-
Constructor Summary
Constructors Constructor Description SocketFactory()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract SocketcreateSocket(InetAddress addr, int port, int timeout)Creates a stream socket and connects it to the specified port number at the specified IP address.abstract SocketcreateSocket(InetAddress addr, int port, InetAddress localAddr, int localPort, int timeout)Creates a socket and connects it to the specified remote host on the specified remote port.static SocketFactorygetDefaultFactory()Returns the SocketFactory singleton for the specified default class.static SocketFactorygetFactory(String sfcn)Returns the SocketFactory singleton for the specified class.static SocketFactorygetSocketFactory()Deprecated.
-
-
-
Field Detail
-
logger
static Logger logger
-
DefaultFactory
public static final String DefaultFactory
The default implementation of the SocketFactory interface is for JDK since 1.4.
-
factoryClasses
private static String[] factoryClasses
-
factory
private static SocketFactory factory
-
-
Method Detail
-
getDefaultFactory
public static SocketFactory getDefaultFactory()
Returns the SocketFactory singleton for the specified default class.- Returns:
- The SocketFactory singleton for the default class.
-
getFactory
public static SocketFactory getFactory(String sfcn)
Returns the SocketFactory singleton for the specified class. If the specified class can not be instantiated the default one is used.- Parameters:
sfcn- The classname for SocketFactory class.- Returns:
- The SocketFactory singleton for the specified class.
-
createSocket
public abstract Socket createSocket(InetAddress addr, int port, int timeout) throws IOException
Creates a stream socket and connects it to the specified port number at the specified IP address. Try to establish the connection to the server with a specified timeout value. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs.- Parameters:
addr- the IP address.port- the port number.timeout- the timeout value to be used in milliseconds.- Returns:
- the created socket.
- Throws:
IOException- if an I/O error occurs when opening the socket.
-
createSocket
public abstract Socket createSocket(InetAddress addr, int port, InetAddress localAddr, int localPort, int timeout) throws IOException
Creates a socket and connects it to the specified remote host on the specified remote port. The Socket will also bind() to the local address and port supplied. Try to establish the connection to the server with a specified timeout value. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs.- Parameters:
addr- the IP address of the remote hostport- the remote portlocalAddr- the local address the socket is bound tolocalPort- the local port the socket is bound totimeout- the timeout value to be used in milliseconds.- Returns:
- the created socket.
- Throws:
IOException- if an I/O error occurs when opening the socket.
-
getSocketFactory
public static SocketFactory getSocketFactory() throws Exception
Deprecated.Returns the SocketFactory singleton. The implementation seems to be choose in an historical way defined by the factoryClasses array.- Returns:
- SocketFactory singleton.
- Throws:
Exception- Cannot find the factory class.
-
-