BlackBerryForums.com : Your Number One BlackBerry Community   TaskMaster for BlackBerry   

»Sponsored Links



Closed Thread
 
LinkBack Thread Tools
  (#1 (permalink)) Old
donricouga Offline
Thumbs Must Hurt
 
Posts: 58
Join Date: Jul 2006
Location: Atlanta
Model: 8703e
Carrier: Sprint
Default Data Push Example ? - 08-01-2006, 07:05 AM

Does anyone have a good data Push example from both the client side and the server side? I'd like to create a MIDlet(Custom Listener) that sits on blackberries and listens to data pushes and upon push, carries out certain tasks. Thanks
   
Sponsored Links
Please Login or Register to Remove these Advertisements!

  (#2 (permalink)) Old
donricouga Offline
Thumbs Must Hurt
 
Posts: 58
Join Date: Jul 2006
Location: Atlanta
Model: 8703e
Carrier: Sprint
Default 08-01-2006, 09:56 AM

Also when I execute this code, nothing in the simulator happens. Only in the MDS window do iI see .' I also get a content length of 0. Oh, and do I have to have A BES Server running as well ??


Quote:
import java.io.*;
import java.net.*;

public class CachePush
{
String MDSAddress = "localhost";

String MDSPort = "8080";
String deviceAddress = "2100000B";
String devicePort = "7874";
String pushType = "Browser-Content";
String contentUrl = "http://127.0.0.1/testpage";
String contentFile = "C:\\jakarta-tomcat-5.0.28\\webapps\\testpage\\sample.htm";

public void run()
{
try
{
// The format of the URL is http://<host>:<port>/push?DESTINATION =<user_email>&PORT=<browser_listen_port&g t;.
URL pushURL = new URL("http", MDSAddress, Integer.parseInt(MDSPort), "/push?DESTINATION="+deviceAddress+"&PORT="+devicePo rt+"&REQUESTURI=/");
HttpURLConnection conn = (HttpURLConnection)pushURL.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("x-rim-push-type", pushType);
conn.setRequestProperty("content-location", contentUrl);
conn.setDoOutput(true);
// For sending the data.
conn.setDoInput(true);
// For receiving the confirmation.
//Get data to push to cache
if (contentFile != null)
{
conn.setRequestProperty("content-type", "text/html");
FileInputStream fis = new FileInputStream(contentFile);
int length = fis.available();
byte[] input = new byte[length];
fis.read(input);
OutputStream os = conn.getOutputStream();
//Write out the file contents
os.write(input, 0, length);
}
else
{
byte[] input = new byte[0];
OutputStream os = conn.getOutputStream();
os.write(input, 0, 0);
}

// Read the response.
InputStream is = conn.getInputStream();
int contentLength = conn.getContentLength();
System.out.println("Content-Length [" + contentLength + "]");
if (contentLength > 0)
{
byte[] byteArray = new byte[contentLength];
DataInputStream dis = new DataInputStream(is);
dis.readFully(byteArray);
System.out.println(new String(byteArray));
}
}
catch (IOException iox)
{
System.err.println(iox);
}
}
public static void main(String[] args)
{
CachePush pushTest = new CachePush();
pushTest.run();
}
}

Last edited by donricouga : 08-01-2006 at 11:07 AM.
   
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




TaskMaster for BlackBerry


Copyright © 2004-2008 BlackBerryNews.com, BlackBerryFAQ.com, BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of Research In Motion Limited.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.1