Sending a message from Symbian C++ to a J2ME MIDlet.
Introduction
A MIDP 2.0 J2ME Midlet registers itself with the push registry to a particular port for receiving incoming SMSes on that port. I have seen many people struggling with trying to send a message from native Symbian application to a J2ME application running on target phone listening. Here is my contribution on how this can be done.
The GSM 3.40 Version 6.0 gives a detailed specification of Short Message Service (SMS) and GSM/UMTS networks. A particular SMS-Deliver type PDU (Protocol Data Unit) has the following elements.
| Abbr. | Reference | Description |
| TP MTI | TP Message Type Indicator | Parameter describing the message type.(2bits) |
| TP MMS | TP More Messages to Send | Parameter indicating whether or not there are more messages to send (1 bit). |
| TP RP | TP Reply Path | Parameter indicating that Reply Path exists. (1 bit) |
| TP UDHI | TP User Data Header Indicator | Parameter indicating that the TP UD field contains a Header. (1 bit) |
| TP SRI | TP Status Report Indication | Parameter indicating if the SME has requested a status report. (1 bit) |
| TP OA | TP Originating Address | Address of the originating SME.(2-12 octets) |
| TP PID | TP Protocol Identifier | Parameter identifying the above layer protocol, if any (1 octet). |
| TP DCS | TP Data Coding Scheme | Parameter identifying the coding scheme within the TP User Data. (1 octet) |
| TP SCTS | TP Service Centre Time Stamp | Parameter identifying time when the SC received the message. (7 octets) |
| TP UDL | TP User Data Length | Parameter indicating the length of the TP User Data field to follow. (Integer) |
| TP UD | TP User Data | Variable length user data. |
Section 9.2.3.24 describes the TP-User Data (TP-UD) field in the SMS PDU. The TP-UD may just contain a message or a User Header along with the message. This is specified by setting the TP-User Data Header Indicator (TP-UDHI) field to appropriate value.
- If the TP UDHI field is ‘0' the TP-UD field contains only data.
- If the TP UDHI field is ‘1' the TP-UD field contains a header along with data.
The User data header contains information in the following format.
| Information Element Identifier | 1 octet |
| Length of Information Element | 1 octet |
| Information Element Data | 0 to "n" octets |
The Information Element is used to convey information such as an indicator of a special SMS, concatenated SMS or the application port addressing scheme. The full list of the various Information Elements can be found in section 9.2.3.24 of the GSM 3.40 specification.
Note: Adding an Information Element eats up the space available for SMS message. Therefore less space is available for your message.
For specifying the destination port number the Information Element to be added is,
| Information Element Identifier | 0x05 |
| Length of Information Element | 0x04 |
| Information Element Data | 0x40, 0x74, 0x00, 0x00 For destination port number 16500 |
Note: Remember if a port number is not specified, then by default the SMS is directed to port zero.
In Symbian, an Information Element can be added to the SMS PDU using;
CSmsInformationElement::TSmsInformationElementIdentifier aIdentifier,
const TDesC8& aData);
Ex:
CSmsHeader& header = smsMtm->SmsHeader();
CSmsSettings& serviceSettings = smsMtm->ServiceSettings();
CSmsPDU& smsPDU = header.Message().SmsPDU();
smsPDU.SetAlphabet(iMsgEncoding);
CSmsUserData& userData = smsPDU.UserData();
TBuf8<4> smsPort;
smsPort.SetLength(4);
smsPort[0] = 0x40; //setting destination port to 16500(0x4074)
smsPort[1] = 0x74;
smsPort[2] = 0x00;
smsPort[3] = 0x00;
userData.AddInformationElementL( CSmsInformationElement::ESmsIEIApplicationPortAddressing16Bit, smsPort );
Note: Adding destination port multiple times will result AddInformationElementL () to throw KErrAlreadyExists. This information element needs to be added only once.
The port numbers ranges from 0 to 65535 and are allocated for various purposes as follows;
| VALUE | ALLOCATED |
| 0-15999 | As allocated by IANA (http://www.IANA.com/) |
| 16000-16999 | Available for allocation by applications |
| 17000-65535 | Reserved |
I have attached a sample J2ME MIDlet for testing. This Midlet registers itself with the Push registry on port 16500 and should be invoked when you send an SMS from your Symbian application.
Enjoy!
Vinay
SE NSS http://xms.za.net/web.html
| Attachment | Size |
|---|---|
| ImportedProject-WMADemo.zip | 28.04 KB |






Sending a message from Symbian C++ to a J2ME MIDlet.
Very good an article, Thanks Vinay.
BR/imcm
Re: Sending a message from Symbian C++ to a J2ME MIDlet.
I defnitely gave up with studying Symbian C++ messages handling, it's too difficult for me, I really think it's a CRAZY handling method...
But this article is very interesting... and it would be even more interesting if, besides the midlet sample, it would also have a c++ sample,:a simple program (possibly a non-GUI program, thus cross-symbian compatible) which just sends an SMS to an hard-coded number and to an hard-coded port.
Is this possible?
I have big difficulties in understanding & compiling & tailoring c++ examples from nokia forum!
Re: Sending a message from Symbian C++ to a J2ME MIDlet.
what is the "iMsgEncoding" you are using in this example?