Class SocketFactory

  • Direct Known Subclasses:
    SSLSocketFactory

    public class SocketFactory
    extends java.lang.Object
    This class creates sockets. It may be subclassed by other factories, which create particular subclasses of sockets and thus provide a general framework for the addition of public socket-level functionality. Socket factories are a simple way to capture a variety of policies related to the sockets being constructed, producing such sockets in a way which does not require special configuration of the code which asks for the sockets:
    • Due to polymorphism of both factories and sockets, different kinds of sockets can be used by the same application code just by passing it different kinds of factories.
    • Factories can themselves be customized with parameters used in socket construction. So for example, factories could be customized to return sockets with different networking timeouts or security parameters already configured.
    • The sockets returned to the application can be subclasses of java.net.Socket, so that they can directly expose new APIs for features such as compression, security, record marking, statistics collection, or firewall tunneling.
    Factory classes are specified by environment-specific configuration mechanisms. For example, the getDefault method could return a factory that was appropriate for a particular user or applet, and a framework could use a factory customized to its own purposes.
    Since:
    TotalCross 1.13
    • Constructor Summary

      Constructors 
      Constructor Description
      SocketFactory()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Socket createSocket​(java.lang.String host, int port)
      Creates a socket and connects it to the specified remote host at the specified remote port.
      Socket createSocket​(java.lang.String host, int port, int timeout)
      Creates a socket and connects it to the specified remote host at the specified remote port.
      static SocketFactory getDefault()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SocketFactory

        public SocketFactory()
    • Method Detail

      • createSocket

        public Socket createSocket​(java.lang.String host,
                                   int port)
                            throws UnknownHostException,
                                   IOException
        Creates a socket and connects it to the specified remote host at the specified remote port. This socket is configured using the socket options established for this factory.
        Parameters:
        host - the server host
        port - the server port
        Returns:
        the Socket
        Throws:
        UnknownHostException - if the host is not known
        IOException - if an I/O error occurs when creating the socket
        Since:
        TotalCross 1.13
        See Also:
        Socket(String, int)
      • createSocket

        public Socket createSocket​(java.lang.String host,
                                   int port,
                                   int timeout)
                            throws UnknownHostException,
                                   IOException
        Creates a socket and connects it to the specified remote host at the specified remote port. This socket is configured using the socket options established for this factory.
        Parameters:
        host - the server host
        port - the server port
        Returns:
        the Socket
        Throws:
        UnknownHostException - if the host is not known
        IOException - if an I/O error occurs when creating the socket
        Since:
        TotalCross 1.22
        See Also:
        Socket(String, int)