Java Reference
In-Depth Information
PushRegistry.registerConnection("socket://:80", PatchyMIDlet, "*");
The first two parameters are pretty clear—any incoming socket connections on port 80
should launch PatchyMIDlet . The third parameter is a filter that will be applied to incoming
connections. In this case, we accept all incoming connections with the * wildcard. Other possi-
bilities would be to restrict incoming connections to a single IP address or a range of addresses.
Remember, the results of the call to registerConnection() persist beyond the lifetime of
the MIDlet. Even after the MIDlet has been destroyed, the MIDlet management software on the
device is watching out for incoming socket connections on port 80. If a connection is received,
PatchyMIDlet will be launched. The push registry doesn't actually do anything with the incoming
connection; it just detects it and launches a registered MIDlet to respond. It's the MIDlet's
responsibility to accept the incoming connection. To find out whether it has been launched by
the push registry or the user, the MIDlet can call PushRegistry 's listConnections() method,
passing true for the available parameter. The method will then return a list of connections
that have input available. If this list is empty, then the MIDlet must have been launched by the
user, not by an incoming connection.
Instead of a MIDlet registering push connections at runtime, it's much more likely that the
push registrations would be contained in the application description for the MIDlet suite
containing PatchyMIDlet . Thus, the push registration would be performed at installation time
so that the user would never need to run the MIDlet manually. In this case, the MIDlet
descriptor would contain a line like this:
MIDlet-Push-1: socket://:80, PatchyMIDlet, *
The parameters are exactly the same. The push registration is made when the MIDlet suite
is installed. If the MIDlet cannot be registered (for example, some other application might
already be listening for incoming socket connections on port 80), then the MIDlet suite will not
be installed. Multiple push registrations are listed in the descriptor using ascending numbers:
MIDlet-Push-1 , MIDlet-Push-2 , and so on.
The J2ME Wireless Toolkit version 2.2 allows you to register and test push connections
easily. Just click the Settings button, and then choose the Push Registry tab. If you downloaded
the source code for this topic, you'll see an entry for PatchyMIDlet . Figure 10-5 shows this entry.
Figure 10-5. The push registry entry for PatchyMIDlet
Search WWH ::




Custom Search