Troubleshooting guide
227
15: Creating push applications
Code sample: Pushing data to an application that listens on a
BlackBerry device
The HTTPPush.java sample application, which uses standard Java™, sends a string of text to a listening client
application on the BlackBerry® device using either a RIM push or a PAP push. The application pushes data based
on an
email address. To test push applications with the BlackBerry device simulator, define a mapping between
the
email address and the BlackBerry device simulator PIN (2100000A).
The following code sample compiles using J2SE 1.4.2.
Example: HTTPPushServer.java
/*
* HttpPushServer.java
* Copyright (C) 2001-2004 Research In Motion Limited. All rights reserved.
*/
package com.rim.samples.docs.httppush;
import java.io.*;
import javax.swing.*;
import javax.swing.border.*;
import java.net.*;
import java.util.*;
import java.awt.Color;
/**
* <p>The HTTPPushServer class provides a simple PUSH server sample.
* <p>This program will send text to a listening device. The associated client demo
* is HTTPPushServer. Start up both the device simulator and MDS before executing
* this program. For reliable push, append the port that you are pushing to in
* rimpublic.property file (push.application.reliable.ports):
* <code>push.application.reliable.ports=7874,<b>100</b></code
*
* <p> The general form of the URL for posting (pushing) data to the device is:
* http://<host>:<port>/push?DESTINATION=<device
pin>&PORT=<device_port>&REQUESTURI=<post uri>
*/
public class HTTPPushServer extends javax.swing.JFrame {
//constants -----------------------------------------------------------------
private static final String RESOURCE_PATH = “com/rim/samples/docs/httppush/resources”;
private static final String DEVICE_PIN = “2100000A”;
private static final String DEVICE_PORT = “100”;
private static final int MDS_PORT = 8080;
private static final String IMAGE_TYPE = “.png”;
private String requestTemplate;
private String notifyURL=”http://localhost:7778”;
private Random random= new Random();
private Thread notificationThread;
//statics -------------------------------------------------------------------
private static ResourceBundle _resources =
java.util.ResourceBundle.getBundle(RESOURCE_PATH);