Proceed to WirelessDevNet Home Page
Publications, e-books, and more! Community Tutorials Store Downloads, tools, & Freebies! IT Career Center News Home
newnav.gif

Newsletters
EMail Address:



   Content
  - Articles
  - Columns
  - Training
  - Library
  - Glossary
 
   Career Center
  - Career Center Home
  - View Jobs
  - Post A Job
  - Resumes/CVs
  - Resource Center
 
   Marketplace
  - Marketplace Home
  - Software Products
  - Wireless Market Data
  - Technical Books
 
   News
  - Daily News
  - Submit News
  - Events Calendar
  - Unsubscribe
  - Delivery Options
 
   Community
  - Discussion Boards
  - Mailing List
  - Mailing List Archives
 
   About Us
  - About WirelessDevNet
  - Wireless Source Disks
  - Partners
  - About MindSites Group
  - Advertising Information
 
WebLinks
  • Simplewire
  • Sending A Wireless Text-Message With Java

    By Joe Lauer (joelauer@simplewire.com), President and Founder of Simplewire. Simplewire is a wireless text-messaging platform capable of messaging across all wireless networks regardless of carrier.

    Printer Friendly Version
    After years of hype, the wireless market is finally upon us. Built upon competitive prices and a large growing user base around the globe, the wireless market is expected to grow at astronomical rates. The GSM Association anticipates monthly global SMS volumes to reach an amazing 25 billion mark by December 2001. (http://www.gsmworld.com/news/press_2001/press_releases_4.html) Fortunately, for application developers, data and information services are experiencing the largest growth levels within the wireless market, thereby bringing new opportunities for revenue. However, even in the midst of “wireless” hype, many developers are still having difficulties navigating around the challenges of the esoteric SMS world. Obstacles such as fragmentation of carriers, inconsistent transport mechanisms and differing message lengths pose numerous complications. Developers who successfully surpass these obstacles are then faced with a new set of difficulties for building a solution in Java.

    Challenges of Sending an SMS Message from Java

    Although SMS (Short Message Service) has proven itself as a robust medium for mobile information, there are many hidden problems preventing developers from using the technology in their applications. SMS is merely a description of services, which wireless carriers provide, rather than a description for a method of delivery. There are many different wireless networks that deliver SMS such as PDC, CDMA, TDMA, GSM or iDEN. These networks communicate over numerous protocols such as SMPP (Short Message Peer-to-Peer), UCP (Universal Computer Protocol), HTTP (Hypertext Transfer Protocol), SMTP (Simple Mail Transport Protocol), etc. Unfortunately, this lack of standards for SMS has increased development learning curves and slowed down adoption rates.

    Inconsistent transports are only a small part of the larger dilemma. Typically, carriers do not allow public access to their networks and some will not even allow private access. This exclusivity leaves developers with very few options. Many developers opt to simply bypass the carrier and implement their own somewhat functional solutions.

    The problem is additionally magnified with the proliferation of various mobile devices, each built with differing technologies and capabilities. Some mobile phones support one-way text-messaging, while others support two-way text-messaging. Some devices are capable of receiving only 140 character messages, while others can receive 600 character messages. Other mobile phones can display images and download binary data, while others cannot. Because of these frustrating differences, the process of sending and receiving wireless messages with mobile devices requires the development and maintenance of extensive technological resources and information about each carrier and every device.

    Aside from the process of sending and receiving text-messages, numerous extended services, which surround wireless devices, are also required in order to realize the full potential offered by today’s wireless technologies. Wireless device metadata is essential in developing and deploying many new applications such as instant messaging, advertisements, location-based services, etc.

    Businesses and consumers are left with ad hoc solutions that fail to unleash the true power of today’s mobile devices. It often becomes cost prohibitive for businesses to integrate emerging wireless technologies into their existing infrastructure. If true communication to any wireless device, regardless of carrier, were possible, many past successes would seem miniscule in light of future opportunities.

    Using SMTP to Send a Text-Message

    Many wireless carriers now expose an SMTP (Simple Mail Transport Protocol) or an email interface to send SMS. In many cases, the email address will typically be the device’s phone number or pager identification number along with the carrier’s special domain. For example, a phone with Sprint PCS service will have an email address of 3135551212@messaging.sprintpcs.com. SMTP is an attractive method of sending SMS. The use of SMTP is free for the sender and software development kits for implementing the protocol are easily accessible.

    Unfortunately, most cost free solutions are littered with drawbacks, particularly in the use of SMTP. Disadvantages of SMTP include the lack of speed, assurance, error checking, features and consistency. By its original design, email was not developed to function as a quick system. As a result, most text-messages sent through email experience latency problems ranging from 1 minute to 2 hours. The speed of an email also relies on a dependable STMP server-one that does not crash somewhere along the path of an email. Email cannot guarantee that the recipient of the message has subscribed to text-messaging in their carrier’s normal service plan.

    Typical SMS lengths range from 80 to 256 characters. Messages delivered via SMTP will normally eliminate portions of the message that go over the maximum character length. In many cases, the most important part of the message will be deleted unknowingly. The code will never discover the mishap. An additional conflict arises within the diversity of email formats used between services. In some instances, only the subject field or body field of a text-message will be used. SMTP code needs to account for these intricacies to assure that certain elements of the message will transmit to the mobile device. The From field showcases another imperfection when using SMTP. This field utilizes up to 20 to 30 characters within an already limited space of 80 to 256 characters.

    Beyond the problems associated with speed and assurance, SMTP fails to expose many of the best features specifically available with SMS such as one-touch callback and presence information (e.g. phone on/off or signal strength).

    Review the following sample Java code in order to learn how SMS might be delivered via SMTP. The following example uses Sun Microsystem’s JavaMail package to implement SMTP.
    
    // Package Imports
    import java.io.*;
    import java.net.InetAddress;
    import java.util.Properties;
    import java.util.Date;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    
    // Public Class
    public class EmailSMS {
    
        // Global Variables
        String              TO;
        String              FROM;
        String              SUBJECT;
        String              TEXT;
        String              MAILHOST;
        String              LASTERROR;
    
        // Main function executed
        public static void main(String[] args) throws Exception {
            EmailSMS SMS = new EmailSMS();
    
            SMS.setMailHost("mail.domain.com");
            SMS.setTo("1234567890@messaging.nextel.com");
            SMS.setFrom("name@domain.com");
            SMS.setSubject("");
            SMS.setText("Hello World!");
            boolean ret = SMS.send();
    
            if (ret) {
                System.out.println("SMS was sent!");
            } else {
                System.out.println("SMS was not sent - " + SMS.getLastError());
            }
        }
    
        // Public Constructor
        public EmailSMS() {
            TO = null;
            FROM = null;
            SUBJECT = null;
            TEXT = null;
            MAILHOST = null;
            LASTERROR = "No method called.";
        }
    
        public void setTo(String to) {
            TO = to;
        }
    
        public String getTo() {
            return TO;
        }
    
        public void setFrom(String from) {
            FROM = from;
        }
    
        public String getFrom() {
            return FROM;
        }
    
        public void setSubject(String subject) {
            SUBJECT = subject;
        }
    
        public String getSubject() {
            return SUBJECT;
        }
    
        public void setText(String text) {
            TEXT = text;
        }
    
        public String getText() {
            return TEXT;
        }
    
        public void setMailHost(String host) {
            MAILHOST = host;
        }
    
        public String getMailHost() {
            return MAILHOST;
        }
    
        public String getLastError() {
            return LASTERROR;
        }
    
        // Will attempt to send the Email SMS and return a boolean meaning it
        // either failed or succeeded.
        public boolean send() {
    
            // Variables to check message length.
            int maxLength;
            int msgLength;
    
            // Check to make sure that the parameters are correct
            if (TO.indexOf("mobile.att.net") > 0) {
                maxLength = 140;
            } else if (TO.indexOf("messaging.nextel.com") > 0) {
                maxLength = 280;
            } else if (TO.indexOf("messaging.sprintpcs.com") > 0) {
                maxLength = 100;
            } else {
                maxLength = 160;
            }
    
            // Calculate message length
            msgLength = FROM.length() + 1 + SUBJECT.length() + 1 + TEXT.length();
    
            // Typically, there are at least two characters of delimiter
            // between the from, subject, and text. This is here to make
            // sure the message isn't longer than the device supports.
            if (msgLength > maxLength) {
                LASTERROR = "SMS length too long.";
                return false;
            }
    
            // Set Email Properties
            Properties props = System.getProperties();
    
            if (MAILHOST != null) {
                props.put("mail.smtp.host", MAILHOST);
            }
    
            // Get a Session object
    		Session session = Session.getDefaultInstance(props, null);
    
            try {
    
                // Construct the email
                Message msg = new MimeMessage(session);
    
                // Set From
                if (FROM != null) {
                    msg.setFrom(new InternetAddress(FROM));
                } else {
                    msg.setFrom();
                }
    
                // Set Subject
                 msg.setSubject(SUBJECT);
    
                // Set Text
                msg.setText(TEXT);
    
                // Add Recipient
                msg.setRecipients(Message.RecipientType.TO,
                                  InternetAddress.parse(TO, false));
    
                // Sent Date
                msg.setSentDate(new Date());
    
    			// Send Email SMS
    			Transport.send(msg);
    
                LASTERROR = "Success.";
                return true;
            } catch (MessagingException mex) {
                LASTERROR = mex.getMessage();
    	    return false;
            }
        }
    }
    
    

    Using a Third-Party Wireless Platform to Send a Text-Message

    If SMTP falls short of easing your wireless pain, then the use of a third-party platform will solve your problem, while hiding the intricacies involved with SMS. Third party solutions often range from shrink-wrapped software to application service provider gateways. One such third-party platform is provided by Simplewire, Inc. Simplewire acts as an operating system between the Internet and any wireless device. Using Simplewire’s Java Software Development Kit allows for the easy integration of powerful text-messaging services. Natively implementing text- messaging services into individual applications forgoes the need to worry about wireless technologies or varying protocols.

    The advantages associated with the use of a third-party platform outweigh several of the short-term yet half-baked benefits of SMTP. Third-party platforms such as Simplewire’s not only can consistently cover every major carrier, but also confirm message delivery while having faster performance than SMTP. The relatively simple solution of using a third-party platform solves a complex wireless problem for numerous developers. The following example demonstrates how to send a text- message using Simplewire’s Java Software Development Kit:
    
    // Imports
    import com.simplewire.sms.*;
    
    // Public Class
    public class SimplewireSMS extends java.lang.Object {
    
        public static void main(String[] args) throws Exception 
        { 
            // Create SMS Object 
            SMS sms = new SMS();
    
            // Set Message Properties 
            sms.setMsgPin("1005101234"); 
            sms.setMsgFrom("Joe"); 
            sms.setMsgCallback("6165551212"); 
            sms.setMsgText("Hello World From Java SMS!"); 
    
            // Display The Status 
            System.out.println("Submitting SMS To Simplewire..."); 
    
            // Send the request to simplewire 
            sms.msgSend(); 
    
            // Check if the request was sent 
            if (sms.isSuccess()) 
            { 
                // Display the status 
                System.out.println( "The message was sent!" ); 
            } 
            // Display the error info 
            else 
            { 
                // Check If Carrier Recognition Error 
                if(sms.getErrorCode().equals("345")) 
                { 
                    System.out.println("Sample request was success."); 
                    System.out.println("However, could not recognize carrier.\n"); 
                } 
                else 
                { 
                    // Display Error Info 
                    System.out.println("The message was not sent!"); 
                    System.out.println("Error Code: " + sms.getErrorCode()); 
                    System.out.println("Error Description: " + sms.getErrorDesc() + "\n"); 
                } 
            } 
        }
    }
    
    

    Conclusion

    The use of third-party solutions and/or shrink-wrapped Java Software Development Kits provides a very simple and efficient mode for sending and receiving SMS. Keep in mind that most solutions will have licensing and usage fees since carriers set their own final pricing. Implementing SMTP will certainly provide a low-priority path to a limited amount of wireless devices, but the amount of email-supporting devices is extremely small on a global scale. The use of SMTP also generates many serious yet hidden conflicts with the delivery of text-messages. If performance, reliability and scalability are important concerns while integrating text-messaging into your own applications, seeking a third-party component may be your best solution!

    About The Author

    Joe Lauer is the founder and president of Simplewire Inc., which provides a wireless text-messaging platform to businesses and consumers. Lauer founded Simplewire to solve the problem of getting wireless text-messages off of the Internet and onto mobile devices. Joe Lauer studied Computer Science and Business at the University of Michigan, Ann Arbor. Mr. Lauer is currently authoring a book on SMS and has written numerous articles on the subject. He can be reached at joelauer@simplewire.com.

    About Simplewire

    Simplewire is a wireless text-messaging platform capable of messaging across all wireless networks regardless of carrier. Our products and services simplify and enhance the way businesses and consumers communicate through all SMS (Short Message Service) phones, RIM devices, two-way and one-way pagers.

    Beyond SMS, our technology delivers numerous extended services such as carrier recognition, device features, delivery confirmation, and device presence (phone on/off).

    Simplewire acts as an operating system between the Internet and any wireless device. With Simplewire, you can easily integrate powerful text-messaging services natively into your own applications or infrastructure via our Software Development Kits or open Application Programming Interface.

    Contact
    Erin Ribiat
    eribiat@simplewire.com
    Chief Evangelist
    Simplewire
    743 Beaubien, Suite 300
    Detroit, MI 48226
    p. 313.879.1000
    f. 313.961.4568
    http://www.simplewire.com

    Does your company have a new or innovative solution that WDN should know about? Send details to editors@wirelessdevnet.com


    Sponsors

    Search

    Eliminate irrelevant hits with our industry-specific search engine!









    Wireless Developer Network - A MindSites Group Trade Community
    Copyright© 2000-2010 MindSites Group / Privacy Policy
    Send Comments to:
    feedback@wirelessdevnet.com