Application or Port Directed SMS: How to Send an SMS to a Java app/MIDlet
It’s a common task, but a confusing one. As Java becomes more widely supported on mobile phones, one of the most obvious application needs is the ability to send SMS messages to an application and have the application take some action based upon the content of the SMS message.
However, while J2ME will let an application receive messages, it will not let the MIDlet interact directly with the phone’s SMS inbox. Instead, applications only receive messages that were addressed to their specific port number. For more information on how to receive these messages from an application running on a phone, refer to the JSR-120 and/or JSR-205 specifications published by the Java Community.
From within your MIDlet, it is relatively easy to send an SMS message to a particular port, because you just include the port number in the recipient address (sms://phonenumber:port).
However, it is not so easy (or in many cases even possible) to send an SMS message to a specific port from a conventional SMS client.
We’ve supported a relatively easy (if obscure) way of sending an SMS message to a specific port in NowSMS since early 2004.
With NowSMS 2007 and later releases, it is easier, as the “Send Text Message” web form will now include a “Destination Port” field. Alternatively, when submitting via a URL request, include “&DestPort=xxxx” or “&SourcePort=xxxx” in the URL request to specify a destination and/or source port. Or, the destination port can be specified in the recipient phone number using the format phonenumber:port. (Note: When using the phonenumber:port format, if multiple recipients are specified, the same destination port will be applied for all recipients, that being the first destination port encountered in the recipient list.)
http://serverip:port/?phone=phonenum&DestPort=3333&text=this+is+a+test
The above example sends a message to port 3333 (hex value, decimal value = 13107). The text of the message is “this is a test”, it has just been URL escaped for encoding in a URL.
From the web form, use the “Send Binary Message Other” form, specify a user data header (UDH) of: 060504xxxxyyyy Where xxxx is the destination port in hex, and yyyy is the source port in hex. (If the source port is not important, replace it with 0′s.) In the “Binary Data” field, put in your text, and leave the DCS as 0. (If you want to send binary data, put the hex string for the binary data in the “Binary Data” field, and use a binary DCS value such as 4.)
If you are posting via direct URL submission, specify the user data header using the parameter “&UDH=060504xxxxxxxx”, and submit the text as you normally would using the “&Text=” parameter.
For example:
http://serverip:port/?phone=phonenum&udh=06050433330000&text=this+is+a+test
The above example sends a message to port 3333 (hex value, decimal value = 13107). The source port in this example is 0. The text of the message is “this is a test”, it has just been URL escaped for encoding in a URL.
Related pages:
- Send SMS from Java (or JSP) A Java example for sending SMS messages via NowSMS has been posted at the following link: http://www.nowsms.com/download/sendsms.java.txt The sendsms class...
- Bug Sending Long Binary SMS Messages to Java Apps on Motorola Devices One of the more interesting technical support incidents of the past week comes from Mohit Kumar Sethi at 3i Infotech...
- Send SMS Text Message with Java The following example Java class, sendsms, can be used to send an SMS text message via NowSMS from Java. This...
- Sending Binary SMS Sending Binary SMS over HTTP To send a binary SMS message via a menu driven interface, please see the help...
- International Prefix Conversion for SMS There are many situations where end users submit messages using local number formats, but the upstream SMSC connection requires that...
- MMS to a Phone Based Application Application Directed MMS: Send an MMS to a Java app/MIDlet In the last post, I talked about sending SMS messages...
- HTTP SMSC The gateway supports the HTTP (Hyper Text Transport Protocol) protocol to connect to an SMSC over the internet or other...
- Send WAP Push from Java (or JSP) The previously posted examples for sending SMS and MMS messages from a Java application with NowSMS can also be used...
- NowSMS as a WAP Push Proxy Gateway NowSMS v5.50 and later support the WAP Push Access Protocol (PAP) to provide the ability to generate more specialised types...
- Creating MMS Message Files Creating MMS Message Files – MMSCOMP The over-the-air MMS message file format is a binary file format, and special tools...
Topic Category: J2ME, Java, Java MIDlet, JSR-205, SMS port addressing
For comments and further discussion, please click here to visit the NowSMS Technical Forums (Discussion Board)...
2 Responses to “SMS to a Port Number”
Trackbacks/Pingbacks
- MMS to a Phone Based Application | NowSMS - [...] the last post, I talked about sending SMS messages to a Java MIDlet running on a phone by using ...

Click here to download a free trial version of NowSMS & MMS Gateway, NowSMS Lite or NowWAP Gateway.
Learn more about NowSMS Lite.
Does this apply to sending an SMS via SMPP.
Thanks
Charles Okwuagwu
>>> Does this apply to sending an SMS via SMPP. < <<
Yes.
It may be worth noting that there are some differences in how different SMPP providers support port addressing, particularly with text (as oppposed to binary) message content.
When you define an SMPP connection in NowSMS, there are 3 different settings that you should try if you experience unexpected results.
By default, NowSMS generates GSM format UDH (User Data Header) for port addressing.
Some SMPP providers expect the text SMS message content to be packed into 7-bit encoding when UDH is present. So if you receive garbage text when you send a message that includes port addressing, try changing the value for the checkbox “Encode long text messages with 7-bit packed encoding” under the “Advanced Settings” for the SMPP connection. (This setting applies not only to long text messages, but it also applies to any text messages that include UDH such as EMS or port addressing.)
Alternatively, some SMPP providers expect you to use the optional SMPP TLV parameters (source_port, dest_port) to specify port addressing. Check the setting “Use TLV parameters for port numbers and segmentation” to configure NowSMS to use this format.
Unfortunately it is often guess work to determine which format your provider expects.
-bn