Class ConnectionManager


  • public class ConnectionManager
    extends java.lang.Object
    The ConnectionManager allows you to open and close remote connections from your application.
    Although its behavior may differ from one platform to another, the objective is to provide a unified process to handle connections across all supported platforms.
    The configuration string received by setDefaultConfiguration is a list of parameters in the format "parameter=value" separated by a semi-colon ";" (spaces are not allowed).

    To configure a GPRS connection, you may provide the following parameters:

    Parameter

    Description

    apn The APN over which the connection will be made.
    username The user name to use to connect to the APN. May be omitted if not required by the specified APN.
    password The password to use to connect to the APN. May be omitted if not required by the specified APN.

    The parameters configured here are automatically used by Socket if the argument params passed to the Socket constructor is null. Otherwise it will ignore the default configuration and attempt to connect using the parameters defined by Socket.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int CELLULAR
      This flag indicates a cellular connection.
      static int CRADLE
      Deprecated.
      Not supported on the newer devices.
      static int GPRS
      Deprecated.
      As of TotalCross 1.20, replaced by CELLULAR.
      static int WIFI
      This flag indicates a Wi-Fi connection.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void close()
      Deprecated.
      Not necessary anymore.
      static java.lang.String getHostAddress​(java.lang.String hostName)
      Returns the IP address of the given host in textual representation, or null if this information is not available.
      static java.lang.String getHostName​(java.lang.String hostAddress)
      Returns the name of the given host, or null if this information is not available.
      static java.lang.String getLocalHost()
      Returns a textual representation of the IP address currently assigned to this device.
      static java.lang.String getLocalHostName()
      Gets the host name for this device.
      static boolean isAvailable​(int type)
      Checks if an specific connection is currently available.
      static boolean isInternetAccessible()
      Returns true if we can connect to google.com using port 80, false otherwise.
      static void open()
      Deprecated.
      Not necessary anymore.
      static void open​(int type)
      Deprecated.
      Not necessary anymore.
      static void setDefaultConfiguration​(int type, java.lang.String configuration)
      Deprecated.
      Not used on the newer devices.
      • Methods inherited from class java.lang.Object

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

      • CRADLE

        @Deprecated
        public static final int CRADLE
        Deprecated.
        Not supported on the newer devices.
        This flag indicates a cradle (USB to PC) connection.
        See Also:
        Constant Field Values
      • WIFI

        public static final int WIFI
        This flag indicates a Wi-Fi connection.
        See Also:
        Constant Field Values
      • CELLULAR

        public static final int CELLULAR
        This flag indicates a cellular connection.
        See Also:
        Constant Field Values
    • Method Detail

      • setDefaultConfiguration

        @Deprecated
        public static void setDefaultConfiguration​(int type,
                                                   java.lang.String configuration)
                                            throws IOException
        Deprecated.
        Not used on the newer devices.
        Used to configure the connection to be used by the application.
        Parameters:
        type - one of the connection type constants defined by the ConnectionManager.
        configuration - list of parameters in the format "parameter=value" separated by a semi-colon ";".
        Throws:
        IllegalArgumentIOException - if type is invalid.
        IOException - if an I/O error occurs while configuring the connection.
        See Also:
        CRADLE, WIFI, CELLULAR
      • isAvailable

        public static boolean isAvailable​(int type)
                                   throws IOException
        Checks if an specific connection is currently available.
        Parameters:
        type - one of the connection type constants defined by the ConnectionManager.
        Returns:
        true if and only if the given connection is available; false otherwise.
        Throws:
        IllegalArgumentIOException - if type is invalid.
        IOException - if an I/O error occurs while checking connection availability.
        See Also:
        CRADLE, WIFI, CELLULAR
      • open

        @Deprecated
        public static void open()
                         throws IOException
        Deprecated.
        Not necessary anymore.
        Attempts to establish a remote connection in the first available connection in the following priority list: CRADLE, WIFI and CELLULAR.
        Throws:
        IOException - if an I/O error occurs while opening the connection.
      • open

        @Deprecated
        public static void open​(int type)
                         throws IOException
        Deprecated.
        Not necessary anymore.
        Attempts to establish a remote connection using the given connection.
        Parameters:
        type - one of the connection type constants defined by the ConnectionManager.
        Throws:
        IllegalArgumentIOException - if type is invalid.
        IOException - if an I/O error occurs while opening the connection.
        See Also:
        CRADLE, WIFI, CELLULAR
      • close

        @Deprecated
        public static void close()
                          throws IOException
        Deprecated.
        Not necessary anymore.
        Attempts to close all open remote connections.
        Throws:
        IOException - if an I/O error occurs while closing a connection.
      • getHostAddress

        public static java.lang.String getHostAddress​(java.lang.String hostName)
                                               throws UnknownHostException
        Returns the IP address of the given host in textual representation, or null if this information is not available.
        Parameters:
        hostName - the host's name.
        Returns:
        the host's IP address in textual representation.
        Throws:
        UnknownHostException - if the given host is unknown or cannot be reached.
      • getHostName

        public static java.lang.String getHostName​(java.lang.String hostAddress)
                                            throws UnknownHostException
        Returns the name of the given host, or null if this information is not available.
        Parameters:
        hostAddress - textual representation of the host's IP address.
        Returns:
        the host's name, or null if the host is unreachable or unknown.
        Throws:
        UnknownHostException - if the given host is unknown or cannot be reached.
      • getLocalHost

        public static java.lang.String getLocalHost()
                                             throws UnknownHostException
        Returns a textual representation of the IP address currently assigned to this device. If this information is not available for any reason, it returns the address "127.0.0.1", which is a reserved address for loopback communication.
        Returns:
        the textual representation of this device's IP.
        Throws:
        UnknownHostException - if the local host is unknown or cannot be reached.
      • getLocalHostName

        public static java.lang.String getLocalHostName()
                                                 throws UnknownHostException
        Gets the host name for this device. If the operation is not allowed, it will return the textual representation of the IP address.
        Returns:
        the host name for this device, or the textual representation of the IP address.
        Throws:
        UnknownHostException
      • isInternetAccessible

        public static boolean isInternetAccessible()
        Returns true if we can connect to google.com using port 80, false otherwise. Please notice this is just a quick check that assumes the device is connected to the Internet without any restrictions. Results are undefined when used behind proxies or firewalls.
        Since:
        TotalCross 1.62