totalcross.net
Class ConnectionManager

totalcross.lang.Object
  extended by totalcross.net.ConnectionManager

public class ConnectionManager
extends totalcross.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.
Currently, this class supports only GPRS connections running on Windows Mobile and BlackBerry.
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.

On BlackBerry, you may instead configure any connection type supported by the device, by passing the parameters defined on the BlackBerry API. (the type of connection to be passed must be GPRS).
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.
Please notice: We cannot guarantee the support of this feature, as their definition, usage and support are defined by RIM. Refer to the BlackBerry documentation or contact RIM for any device specific issue.


Field Summary
static int CELLULAR
          This flag indicates a cellular connection.
static int CRADLE
          This flag indicates a cradle (USB to PC) connection.
static int GPRS
          Deprecated. As of TotalCross 1.20, replaced by CELLULAR.
static int WIFI
          This flag indicates a Wi-Fi connection.
 
Method Summary
static void close()
          Attempts to close all open remote connections.
static String getHostAddress(String hostName)
          Returns the IP address of the given host in textual representation, or null if this information is not available.
static String getHostName(String hostAddress)
          Returns the name of the given host, or null if this information is not available.
static String getLocalHost()
          Returns a textual representation of the IP address currently assigned to this device.
static boolean isAvailable(int type)
          Checks if an specific connection is currently available.
static void open()
          Attempts to establish a remote connection in the first available connection in the following priority list: CRADLE, WIFI and CELLULAR.
static void open(int type)
          Attempts to establish a remote connection using the given connection.
static void setDefaultConfiguration(int type, String configuration)
          Used to configure the connection to be used by the application.
 
Methods inherited from class totalcross.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CRADLE

public static final int CRADLE
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

GPRS

public static final int GPRS
Deprecated. As of TotalCross 1.20, replaced by CELLULAR.
See Also:
Constant Field Values
Method Detail

setDefaultConfiguration

public static void setDefaultConfiguration(int type,
                                           String configuration)
                                    throws IOException
Used to configure the connection to be used by the application. Note: PalmOS does not support this operation for CELLULAR connections.

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

public static void open()
                 throws IOException
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

public static void open(int type)
                 throws IOException
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

public static void close()
                  throws IOException
Attempts to close all open remote connections.

Throws:
IOException - if an I/O error occurs while closing a connection.

getHostAddress

public static String getHostAddress(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 String getHostName(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 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.