Class SocketFactory

  • Direct Known Subclasses:
    SocketFactory13, SocketFactory14

    public abstract class SocketFactory
    extends Object
    This class wraps multiples implementations of the java.net.Socket class.
    • 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
    • Constructor Detail

      • SocketFactory

        public SocketFactory()
    • 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 host
        port - the remote port
        localAddr - the local address the socket is bound to
        localPort - the local port the socket is bound to
        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.
      • 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.