com.motorola.oem.ipd
Class LocalSocketManager

java.lang.Object
  extended by OEM
      extended by com.motorola.oem.ipd.LocalSocketManager

public class LocalSocketManager
extends OEM

Local sockets managment.

 

Definition

A local socket is an IP based socket, which bounds a server/client that resides in the MIDlet, to a remote client/server resides in an external device, over a Serial connectivity.

Both sides use preset local IP addresses to communicate with each other.
For client mode local sockets, external device's IP address should be retrieved by getRemoteAddress() method.
For server mode local sockets, listen port should be retrieved by getListenPort() method.
In order to open a local socket, these IP and/or port should be used as host and port parameters in the connection scheme of the following standard MIDP interfaces:
SocketConnection,
ServerSocketConnection,
DatagramConnection,
UDPDatagramConnection,
HttpConnection,
HttpsConnection,
SecureConnection

For example:
// Retrieve the local listen port
int localPortId = LocalSocketManager.getListenPort();
// open TCP server local socket
ServerSocketConnection ssc = (ServerSocketConnection)Connector.open("socket://:"+localPortId);


This class will provide a set of access methods to acquire/set connection parameters which are necessary prior to local socket opening.

See Also:
IpDirectorAvailabilityListener

Field Summary
static int IPD_STATE_ACTIVE
          IP Director service is ready for use.
static int IPD_STATE_INACTIVE
          IP Director service is not available.
 
Method Summary
static int getIpdState()
          Get the current IP Director service availability state.
static int getListenPort()
          Gets the local listen socket fixed port id.
static java.lang.String getOwnAddress()
          Gets the Local Socket own fixed IP.
static java.lang.String getRemoteAddress()
          Gets the Local Socket remote fixed IP.
static void setIpDirectorListener(IpDirectorAvailabilityListener listener)
          Sets the listener for IP Director state changed event.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IPD_STATE_INACTIVE

public static final int IPD_STATE_INACTIVE
IP Director service is not available.
 
Any opened local socket must be closed.

See Also:
IpDirectorAvailabilityListener.onIpdStateChanged(int), IPD_STATE_ACTIVE, Constant Field Values

IPD_STATE_ACTIVE

public static final int IPD_STATE_ACTIVE
IP Director service is ready for use.
 
local socket(s) can be opened

See Also:
IpDirectorAvailabilityListener.onIpdStateChanged(int), IPD_STATE_INACTIVE, Constant Field Values
Method Detail

getIpdState

public static final int getIpdState()
Get the current IP Director service availability state.

Returns:
One of the following values: IPD_STATE_INACTIVE, IPD_STATE_ACTIVE
See Also:
IpDirectorAvailabilityListener.onIpdStateChanged(int)

getRemoteAddress

public static java.lang.String getRemoteAddress()
Gets the Local Socket remote fixed IP.
 
That is, external device's preset IP address, as configured by AT+MIAU command.
This IP may be used for TCP/UDP socket(s) opening in client mode.

Usage example:
// UDP
UDPDatagramConnection dc = (UDPDatagramConnection)Connector.open("datagram://"+LocalSocketManager.getRemoteAddress()+":"+anyPortId);
// TCP
SocketConnection ssc = (SocketConnection)Connector.open("socket://"+LocalSocketManager.getRemoteAddress()+":"+anyPortId);

Returns:
remote IP string in IPv4 format

getOwnAddress

public static java.lang.String getOwnAddress()
Gets the Local Socket own fixed IP.
 
That is, MIDlet's preset local IP address, as configured by the External device (see device User Guide).

Returns:
MIDlet's own local IP string in IPv4 format

getListenPort

public static int getListenPort()
Gets the local listen socket fixed port id.
 
That is, MIDlet's preset local port, as configured by the External device (see device User Guide). This port id may be used for TCP/UDP socket(s) opening in server mode.
Usage example:
// Retrieve the listen port
int localPortId = LocalSocketManager.getListenPort();
// UDP
UDPDatagramConnection dc = (UDPDatagramConnection)Connector.open("datagram://:"+localPortId);
// TCP
ServerSocketConnection ssc = (ServerSocketConnection)Connector.open("socket://:"+localPortId);

Returns:
port id

setIpDirectorListener

public static void setIpDirectorListener(IpDirectorAvailabilityListener listener)
Sets the listener for IP Director state changed event.
 
User can reconfigure existing listener at any time.

 Note: Setting a null listener will cancle the listening on IP Director events.

Parameters:
listener - External listener object to receive the event.
See Also:
IpDirectorAvailabilityListener