Java Reference
In-Depth Information
MIDlet-Push-<n>: <ConnectionUrl>, <MIDletClassName>, <AllowedSender>
The first entry
MIDlet-Push-<n>
is used for numbering the push MIDlets in a given suite. The
ConnectionUrl
defines the protocol and parameters of inbound connections the AMS should listen
for. The
MIDletClassName
parameter contains the class name of the MIDlet that should be started
if an inbound connection on the given URL was detected. The
AllowedSender
parameter may be
used to restrict connections to the MIDlet. In case of IP connections the allowed senders may be
specified by an IP number including wildcards. A single * allows access from any client.
If the client is allowed to connect to the MIDlet, the AMS starts the MIDlet by calling the
startApp()
method. After the MIDlet is started, it needs to handle the connection itself. For instance, in order to
register a MIDlet called
MIDPHttpServer
, the corresponding jad entry allowing all clients to
connect would look as follows:
MIDlet-Push-1: socket://:80, MIDPHttpServer, *
Another approach to register a MIDlet to inbound connection is to call the
registerConnection()
method from the
PushRegistry
class dynamically. The previously mentioned descriptor file entries
are passed as
String
parameters to the method. In both cases the
startApp()
method is called if
an inbound connection is detected by the AMS.
Since the
startApp()
method has no parameter for passing the inbound connection, the MIDlet
needs to query the inbound connection. For querying the inbound connections currently waiting to be
handled, the
PushRegistry.listConnctions()
method is provided. This method takes one
boolean parameter as flag.
True
indicates that the
String
array returned by the method should
contain connections with input data that requires handling only. If
false
is passed to the method, all
connections registered to the given
MIDletSuite
are returned.
The following sample code snippet shows how to handle a previously registered inbound socket
connection:
public void startApp() {
String availableConnections[];
availableConnections = PushRegistry.listConnections(true);
if (availableConnections.size() > 0) {
}
try {
// since the socket connection is the only connection
// we want to listen to we can simply pass the result String
// containing the Connector.open() method.
StreamConnection sconn = (StreamConnection)Connector,open();
InputStream is = sconn.opeInputStream();
// read input data here
is.close();
sconn.close();
}
catch (IOEXception ioe) {
// handle a possible error during establishing the connection
}
}
Note
Search WWH ::
Custom Search