Package totalcross.net
Class ConnectionManager
- java.lang.Object
-
- totalcross.net.ConnectionManager
-
public class ConnectionManager extends java.lang.ObjectThe 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
apnThe APN over which the connection will be made. usernameThe user name to use to connect to the APN. May be omitted if not required by the specified APN. passwordThe 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 intCELLULARThis flag indicates a cellular connection.static intCRADLEDeprecated.Not supported on the newer devices.static intGPRSDeprecated.As of TotalCross 1.20, replaced byCELLULAR.static intWIFIThis flag indicates a Wi-Fi connection.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidclose()Deprecated.Not necessary anymore.static java.lang.StringgetHostAddress(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.StringgetHostName(java.lang.String hostAddress)Returns the name of the given host, or null if this information is not available.static java.lang.StringgetLocalHost()Returns a textual representation of the IP address currently assigned to this device.static java.lang.StringgetLocalHostName()Gets the host name for this device.static booleanisAvailable(int type)Checks if an specific connection is currently available.static booleanisInternetAccessible()Returns true if we can connect to google.com using port 80, false otherwise.static voidopen()Deprecated.Not necessary anymore.static voidopen(int type)Deprecated.Not necessary anymore.static voidsetDefaultConfiguration(int type, java.lang.String configuration)Deprecated.Not used on the newer devices.
-
-
-
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
-
GPRS
@Deprecated public static final int GPRS
Deprecated.As of TotalCross 1.20, replaced byCELLULAR.- See Also:
- Constant Field Values
-
-
Method Detail
-
setDefaultConfiguration
@Deprecated public static void setDefaultConfiguration(int type, java.lang.String configuration) throws IOExceptionDeprecated.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- iftypeis 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 IOExceptionChecks 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- iftypeis invalid.IOException- if an I/O error occurs while checking connection availability.- See Also:
CRADLE,WIFI,CELLULAR
-
open
@Deprecated public static void open() throws IOExceptionDeprecated.Not necessary anymore.Attempts to establish a remote connection in the first available connection in the following priority list:CRADLE,WIFIandCELLULAR.- Throws:
IOException- if an I/O error occurs while opening the connection.
-
open
@Deprecated public static void open(int type) throws IOExceptionDeprecated.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- iftypeis invalid.IOException- if an I/O error occurs while opening the connection.- See Also:
CRADLE,WIFI,CELLULAR
-
close
@Deprecated public static void close() throws IOExceptionDeprecated.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 UnknownHostExceptionReturns 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 UnknownHostExceptionReturns 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 UnknownHostExceptionReturns 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 UnknownHostExceptionGets 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
-
-