BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 05-23-2011, 11:57 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Mar 2011
Model: 8900
PIN: N/A
Carrier: Torch
Posts: 59
Post Thanks: 3
Thanked 1 Time in 1 Post
Default Hello

Please Login to Remove!

Hello,

I am developing client side push application in blackberry but i didnt receive any push message from server side . My code is :

i am calling listening thread in the constructor of class that extends UiApplication before push screen. i am appending port, applicaiotion id in url as:

url = "http://:24563?applicationid=6783-456gtuwxcttttyf84ytrgjuyu&osversion="+ osVersion + "&model=" + model;


private class ListeningThread extends Thread

{
private String URL = "";
private static final int CHUNK_SIZE = 256;
private boolean _stop = false;
private StreamConnectionNotifier _notify;

public ListeningThread(String url){
this.URL=url;
}


public synchronized void stop() {
_stop = true;
try {
// Close the connection so the thread will return.
_notify.close();
} 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;
MDSPushInputStream pushInputStream = null;
while (!_stop) {
try {
// Synchronize here so that we don't end up creating a
// connection
// that is never closed.
synchronized (this) {

// Open the connection once (or re-open after an
// IOException), so we don't end up
// in a race condition, where a push is lost if it comes in
// before the connection
// is open again. We open the url with a parameter that
// indicates that we should
// always use MDS when attempting to connect.
HttpClient con=new HttpClient();
_notify = con.getStreamConnectionNotifier(URL);
}
while (!_stop) {

// NOTE: the following will block until data is received.
stream = _notify.acceptAndOpen();
try {
input = stream.openInputStream();
pushInputStream = new MDSPushInputStream(
(HttpServerConnection) stream, input);
// 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);
}
updateMessage(data);
// This method is called to accept the push.
pushInputStream.accept();
input.close();
stream.close();
data = db.getArray();
} catch (IOException e1) {
// A problem occurred with the input stream , however,
// the original
// StreamConnectionNotifier is still valid.
System.err.println(e1.toString());
if (input != null) {
try {
input.close();
} catch (IOException e2) {
}
}
if (stream != null) {

try {
stream.close();
} catch (IOException e2) {
}
}
}
}
_notify.close();
_notify = null;
} catch (IOException ioe) {
// Likely the stream was closed. Catches the exception thrown by
// _notify.acceptAndOpen() when this program exits.
if (_notify != null) {
try {
_notify.close();
_notify = null;
} catch (IOException e) {
}
}
}
}
}

private void updateMessage(final byte[] data) {
Application.getApplication().invokeLater(new Runnable() {
public void run() {
// Query the user to load the received message.
String[] choices = { "Ok", "Cancel" };
if (0 != Dialog.ask(
"New message received. Do you want to render it?",
choices, 0)) {
return;
}

Dialog.alert("Text received - size: " + data.length);
try {
Dialog.alert(new String(data));
} catch (Exception e) {
Dialog.inform(e.toString());
System.err.println(e.toString());
}
}
});
}

protected void onExit() {
// Kill the listening thread.
_listeningThread.stop();
try {
_listeningThread.join();

} catch (InterruptedException e) {
System.err.println(e.toString());
}
}

}


Is there some thing wrong with my code. I might be not providing url correctly or some thing might be missing from my code.

Any one have any idea?
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

FP073600AV Campbell Hausfeld Air Compressor Pressure Switch Set 95-125# New
$23.6
FP073600AV Campbell Hausfeld Air Compressor Pressure Switch Set 95-125# New pictureLitton with (4) Switching Kepco DC Power Supply's 285613-1
$161.5
Litton  with (4) Switching Kepco DC Power Supply's 285613-1 pictureGroenlo Holland Switching Power Supply 9833358
$76.0
Groenlo Holland Switching Power Supply 9833358 picture1967 Lot 6 Vector Model 1030-S4 Power Switches - new in pkg
$14.69
1967 Lot 6 Vector Model 1030-S4 Power Switches - new in pkg picturePC Switching Power Supply PS80
$57.0
PC Switching Power Supply PS80 picture






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