Topic Keywords: J2ME, Java, Java MIDlet, JSR-205, SMS port addressing
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.
For comments and further discussion, please click here to visit the NowSMS Technical Forums (Discussion Board)...
2 Responses to “SMS to a Port Number”
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