Troubleshooting guide

217
15: Creating push applications
Write a client push application
Task Steps
Create a listening thread. > Send and receive data on a separate thread so that you do not block the main event.
Determine if a BlackBerry® device is in
a wireless coverage area.
1. Create code to check if the IPPP service book can be routed.
if( ServiceBook.getSB().getRecordByUidAndCid( serviceUID, "IPPP" ) ==
null ) {
// There is no service book
return false;
}
if( ServiceRouting.getInstance().isServiceRoutable( serviceUID, -1 )
) {
// Serial bypass is active
return true;
}
2. Create code to check that the wireless transceiver is on and that data coverage is on.
return RadioInfo.getState() != RadioInfo.STATE_OFF
&& ( RadioInfo.getNetworkService() &
RadioInfo.NETWORK_SERVICE_DATA ) != 0;
Open an input stream. 1. Invoke Connector.open(String), specifying http:// as the protocol and choosing a high
port number from 1 to 65,535 to avoid conflicts with other applications. You cannot use the
following port numbers:
80
443
7874
8080
Connnector.open(http://6234);
2. To specify the connection type that the application uses for incoming and outgoing connections,
at the end of the connection string, add a colon, followed by the optional
deviceside=<boolean> parameter with one of the following values:
If the application listens for push information from BlackBerry MDS™ Services, set the
deviceside=<
boolean> parameter to false.
If the application listens for push information from WAP push requests, do not use the
deviceside=<
boolean> parameter.
3. Cast the object that Connector.open returns as a StreamConnectionNotifier.
StreamConnectionNotifier _notify =
(StreamConnectionNotifier)Connector.open("http://:6234");
4. Open a server-side stream connection once and keep the server-side stream connection open.
// open a server-side stream connection
StreamConnection stream = _notify.acceptAndOpen();
// open an input stream for the connection
InputStream input = stream.openInputStream();
5. Read the incoming data.
6. If you use application-level push reliability, use the pushInputStream.accept() method to
accept and acknowledge the incoming data.
7. If an IOException occurs, reopen the connection.