Blackberry RIM Push


With Blackberry RIM push, you send push message using html header request instead of XML. It can only used with Blackberry Enterprise Server

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;

namespace rim_push
{
class push
{
String _param;
byte[] data = null;
public push(String param)
{
_param = param;
}
public void httpPush(string BESAddress, string BESWebserverListenPort,
string pushTitle, string url, string pushPin)
{
string pushPort = “100”;
string httpURL = “http://”+ BESAddress +”:”+ BESWebserverListenPort +”/push?DESTINATION=”+ pushPin +”&PORT=”+ pushPort +”&REQUESTURI=/”;
try
{
HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(httpURL);
HttpWReq.Method = (“POST”);
HttpWReq.Headers.Add(“Content-Location”, url);
HttpWReq.Headers.Add(“X-RIM-Push-Title”, pushTitle);
data = StrToByteArray(_param);
HttpWReq.ContentLength = data.Length;
Stream requestStream = HttpWReq.GetRequestStream();
requestStream.Write(data, 0, data.Length);
HttpWebResponse HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();
requestStream.Close();
HttpWRes.Close();
}
catch (System.Exception e)
{
}
}
public static byte[] StrToByteArray(string str)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetBytes(str);
}
}
}

If you use a Blackberry simulator, you need an MDS running to see the result with Blackberry simulator

First add this code as listener to your button:

private void button1_Click(object sender, EventArgs e)
{
push push = new push(textBox1.Text);
push.httpPush(“localhost”, “8080”,  “x”, “localhost:8080″,”2100000A”);
}

make sure you can access localhost:8080 in your computer, thats mean your MDS is running. The default pin number is 2100000A, be sure the number is still the default.

About abunajiyah
A Programmer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: