Java Reference
In-Depth Information
Listing 14-3.
Some Hypothetical MIDlet-Push Entries
MIDlet-Push-1: socket://:7, com.apress.rischpater.EchoMIDLet, *
MIDlet-Push-2: socket://:80, com.apress.rischpater.HttpMIDlet, 192.168.1.128
MIDlet-Push-3: sms://:1234, com.apress.rischpater.SMSMIDlet, +1123456????
As you can see from the example, the permissible sender entry can contain wild-
cards; just like with file names in most shells today, you can use
*
to specify one or more
characters, and
?
to specify a single character.
■
Note
Using the push registry requires privilege; be sure you include the appropriate privileges for the GCF
end points you're using in the
MIDlet-Permissions
entry of your MIDlet's JAD file.
When the AMS launches your application in response to an inbound connection
request such as an MT message, the AMS adds the GCF URL of the inbound connection
to a list. You can request this list using the
PushRegistry
class's
listConnections
method,
which returns a list of inbound connections. This is actually
more
information than you
need, because it lists all inbound end points on which the AMS is listening for your
MIDlet. By passing
true
, you receive a list of only those end points with pending connec-
tions bearing data. Listing 14-4 shows some pseudocode that does this.
Listing 14-4.
Using the PushRegistry's listConnections Method
private boolean processIncomingRequests() {
String[] connections =
PushRegistry.listConnections(true);
if (connections != null && connections.length > 0) {
for (int i=0; i < connections.length; i++) {
c = (MessageConnection) Connector.open(connections[i]);
Message m = c.receive();
if (m instanceof TextMessage) {
processOneMessage((TextMessage)m);
}
}
return(true);
}
return(false);
}