Browse DevX
Sign up for e-mail newsletters from DevX


Open the Mobile Gateway with SMS and MMS Messaging : Page 3

If you've ever used your mobile device to check your Yahoo! Mail or check the news, you've used a Short Messaging Service (SMS). This article takes you through the inner-workings of these near-ubiquitous services, finally demonstrating how to SMS-enable your weblog.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

The MMS-to-Web Gateway
Just as you implemented an SMS gateway, you can implement an MMS (Multimedia Messaging Service) gateway. What's the difference between an SMS and an MMS?

SMS messages can only contain text/plain messages, while emails sent using MMSes have textual as well as multimedia data (typically images). Thus, MMS messages are "multipart" messages—the MIME type part of the email could be text/plain, and the other part could be an image/jpeg.

So the only difference between an SMS gateway and an MMS gateway is in how each handles the various MIME extensions of the email.

Note: In an SMS message, the MIME type can be text/plain only, so you don't have to explicitly handle such email messages.

The MMS gateway is identical to the scheme shown above for the SMS gateway.

Listing 2 shows how to implement the MMS gateway as pseudocode.

SMS-to-LiveJournal: An SMS-to-Web Gateway
For those of you who have not heard of LiveJournal, it's a very popular blogging Web site that runs on open-source software. I recently wrote an SMS-to-LiveJournal gateway (simply called SMS2LJ). The source—written in Python—is available under the terms of the GNU Public License (GPL) at http://ljtools.sourceforge.net/.

This tool is similar to the SMS-to-Web gateway that I discussed earlier. Where it differs is in the service provided—using this tool, a user can send an SMS, which then is processed by the gateway, but instead of simply displaying the message on the computer, the message is posted to your LiveJournal account. This allows you to post to your LiveJournal account whenever you are on the move.

Instead of using the display() function, you use the postToLiveJournal() function:

function postToLiveJournal(what) { server = "http://www.livejournal.com/"; data = { user: LJ_USER, password: LJ_PASSWORD, subject: "", message: what, year: time.getYear(), month: time.getMonth(), day: time.getDay(), time_hrs: time.getHours(), time_mins: time.getMinutes() } XMLRPC.post(data, server); }

Author's Note: In the above pseudocode, the main functions run in an infinite while loop (with some "sleep" period). This was to demonstrate the idea behind how these gateways run continuously, polling whatever they are supposed to (POP3 mailboxes, etc.). However, using an infinite while loop is not a very good idea. Instead, when actually using the script, run the main function only once in the script, and schedule the script using a scheduler like cron.

Using a scheduler makes more sense. If you use a while loop instead, and if for some reason an error occurs, the script would halt. Thus, your gateway will no longer work until you re-run it. Errors in scripts are very common. To avoid such problems, use a scheduler. Even if an error occurs at a particular run, the script will be scheduled to run again.

Using Mobile-to-Web Gateways
The above example (SMS-to-LiveJournal Gateway), shows how to perform "moblogging," or, blogging on the move. An even better way to achieve moblogging is to send multimedia messages using your mobile device—an MMS-to-LiveJournal Gateway. For those interested, I have written one (using Ruby). It’s available here.

There are plenty of ways you could use Mobile-to-Web Gateways:

  • Comment Alert: Most blogging tools allow readers to leave comments to your posts. You can easily create an application that would alert you (by way of SMS or MMS) when you receive a comment. This can be easily achieved by "parsing" your comments page, or even better using an API (if one is available) to keep track of comment counts.
  • Mail Alert: Another very interesting way to use Mobile Gateways is to create a mobile mail alert application. This application would in essence, poll your POP3 mailbox for incoming mails, and when one arrives, it would simply send an email to your gateway address (typically of the form your-mobile-number@your-service-provider). This would make an interesting application for those on the move with handheld mobile devices. In fact, you could even message the entire text of the email, limited, of course, only by the SMS/MMS character limit imposed by your mobile phone operator.
  • Using such gateways, you could provide your own mobile service. For example, you could provide topical news. How? Well, you'd have a primary email address that acts as the target "address" to obtain a news service. People who want the service could simply send a message to that mail address, a typical message being of the form: news whetever-category. Your gateway simply polls your POP3 mailbox for such messages, parses them, and accordingly delivers the services!
There are many other useful ways to use gateways; if you think of one, drop me a line. I hope this article has helped you understand the idea behind gateways.

Premshree Pillai is an open source technologist and freelance writer from Mumbai, India. He likes to evangelize the use of Python for development. He blogs here.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date