BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-18-2007, 02:40 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 7100T
PIN: N/A
Carrier: Hutch
Posts: 20
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question Reliable Push Application ....

Please Login to Remove!

HI,

I am developing client/server push application. using simulator its working fine.

But I have few question :-

What about push data sent to the device client side application is not running or device is out of coverage ?

Will MDS take care of resending push data(push request) to the device ?

or we need to develop strategy to handle reliable delivery of push data ?


Regards,
Amit
Offline  
Old 07-19-2007, 10:28 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 7100T
PIN: N/A
Carrier: Hutch
Posts: 20
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I hope the thread doesn't die without any reply............ Has nobody got some answer to such questions in past ? ....If yes plz help me out...
Offline  
Old 07-20-2007, 06:48 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: TDC
Posts: 115
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by amitinc View Post
I hope the thread doesn't die without any reply............ Has nobody got some answer to such questions in past ? ....If yes plz help me out...
well... the device SHOULD give you back a response if data has been received successfully... check out this sample code.... around the if (content

HOWEVER... i have not yet seen a contnent length being anything but 0. I assume its due to me running on simulator. Can someone confirm that??



SERVER CODE


import java.io.*;
import java.net.*;
import java.util.*;

class HTTPPushSDemo {

//constants
private static final String HANDHELD_EMAIL = "2100000A";
private static final String HANDHELD_PORT = "100";
private static final String BES_HOST = "localhost";
private static final int BES_PORT = 8080;
private static final String CONTENT = "c:/landskronagade.png";

//constructor
public HTTPPushSDemo() {
}

private static URL getPushURL(String HandheldEmail) {
URL _pushURL = null;
try {
if ((HandheldEmail == null) || (HandheldEmail.length() == 0)) {
HandheldEmail = HANDHELD_EMAIL;
}
_pushURL = new URL("http", BES_HOST, BES_PORT,
"/push?DESTINATION="+ HandheldEmail
+"&PORT="+HANDHELD_PORT+"&REQUESTURI=/");
} catch (MalformedURLException e) {
System.err.println(e.toString());
}
return _pushURL;
}
public static void postData(byte[] data) {
try {
URL url = getPushURL(HANDHELD_EMAIL);
System.out.println("Sending to" + url.toString());
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoInput(true); //for receiving the confirmation
conn.setDoOutput(true); //for sending the data
conn.setRequestMethod("POST"); //post the data to the BES
OutputStream out = conn.getOutputStream();
out.write(data); //write the data
out.close();
InputStream ins = conn.getInputStream();
int contentLength = conn.getContentLength();
System.out.println("Content length: "+ contentLength);
if (contentLength > 0) {
byte[] someArray = new byte [contentLength];
DataInputStream dins = new DataInputStream(ins);
dins.readFully(someArray);
System.out.println(new String(someArray));
}
ins.close();
conn.disconnect();
} catch (IOException e) {
System.err.println(e);
}
}
public static void main (String args[]) {
try {
File f = new File(CONTENT);
if ( f == null ) {
throw new RuntimeException("Unable to Open File");
}
FileInputStream fi = new FileInputStream(f);
if ( null == fi ) {
throw new RuntimeException("Unable to open file");
}
int size = fi.available();
byte[] imageData = new byte[size];
int bytesRead = fi.read(imageData);
fi.close();
postData(imageData);
} catch (IOException e) {
System.err.println(e.toString());
}
}
}







CLIENT CODE


/**
* HTTPPushDemo.java
* Copyright (C) 2001-2004 Research In Motion Limited. All rights reserved.
*/

package com.rim.samples.docs.httppush;

import java.io.*;
import javax.microedition.io.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.i18n.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;
import com.rim.samples.docs.baseapp.*;

public class HTTPPushDemo extends BaseApp {
// Constants.
private static final String URL = "http://:100";
private static final int CHUNK_SIZE = 256;

// Fields.
private ListeningThread _listeningThread;
private MainScreen _mainScreen;
private RichTextField _infoField;
private BitmapField _imageField;

public static void main(String[] args) {
HTTPPushDemo theApp = new HTTPPushDemo();
theApp.enterEventDispatcher();
}

/**
* Create a separate listening thread so that you do not
* block the application's main event thread.
*/
private class ListeningThread extends Thread {
private boolean _stop = false;
private StreamConnectionNotifier _notify;

public synchronized void stop() {
_stop = true;
try {
_notify.close(); // Close the connection so thread returns.
} catch (IOException e) {
System.err.println(e.toString());
} catch (NullPointerException e) {
// The notify object likely failed to open, due to an IOException.
}
}
public void run() {
StreamConnection stream = null;
InputStream input = null;
try {
synchronized(this) {
// Open the connection once or re-open after an IOException.
_notify = (StreamConnectionNotifier)Connector.open(URL);
}
while (!_stop) {
// NOTE: This method blocks until data is received.
stream = _notify.acceptAndOpen();
input = stream.openInputStream();

// Extract the data from the input stream.
DataBuffer db = new DataBuffer();
byte[] data = new byte[CHUNK_SIZE];
int chunk = 0;
while ( -1 != (chunk = input.read(data)) ) {
db.write(data, 0, chunk);
}
input.close();
data = db.getArray();
updateBitmap(data);
}
} catch (IOException e) {
System.err.println(e.toString()); // It is likely the stream was closed.
}
}
}
// Constructor.
public HTTPPushDemo() {
_mainScreen = new MainScreen();
_mainScreen.setTitle(new LabelField("Latest Logos", LabelField.USE_ALL_WIDTH));
_infoField = new RichTextField();
_mainScreen.add(_infoField);
_mainScreen.add(new SeparatorField());
_imageField = new BitmapField(null, BitmapField.HCENTER|BitmapField.TOP);
_mainScreen.add(_imageField);
_mainScreen.addKeyListener(this);
_mainScreen.addTrackwheelListener(this);

_listeningThread = new ListeningThread();
_listeningThread.start();

_infoField.setText("Application is listening...");
pushScreen(_mainScreen);
}
private void updateBitmap(final byte[] data) {
Application.getApplication().invokeLater(new Runnable() {
public void run() {
// Query the user to load the received image.
String[] choices = {"OK", "CANCEL"};
if ( 0 != Dialog.ask("Do you want to display latest logo?",
choices, 0) ) {
return;
}

_infoField.setText("Image received. Size: "+ data.length);
_imageField.setBitmap(Bitmap.createBitmapFromPNG(d ata, 0,data.length));
}
});
}
protected void onExit() {
// Stop the listening thread.
_listeningThread.stop();
try {
_listeningThread.join();
} catch (InterruptedException e) {
System.err.println(e.toString());
}
}
}
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.