Friday, September 1, 2006


First published 2003 sometime!

GSMS is a very simple attempt to send and recieve SMS via a GSM modem. Generally it should also work correctly with a GPRS modem. You can use:

  • A modem as those from Wavecom
  • You mobile phone over infra-red (iR)
  • Your mobile phone connected to your PC by a cable

Generally all newer phones support their use as a GSM Modem so check with your phone manual. In all cases you need to know the Serial Port you connect your device to, such as COM2,COM3 etc and then connect to it.

To use this API you need the Java Comm API that you can download from Follow CLOSELY the instructions for installing the comm API otherwise it wont work. Look for the jdk1.2.html         file for installing help when using J2SE1.2 and later.

A code snippet to help you get started. Download here.

import java.util.*;
import javax.comm.*;

//import packages

public static void main(String[] args){
    GSMModem myModem;
        myModem=new GSMModem("COM2",CONST.CONNECT_BAUD_9600);
        //see wat modem i have
        //send sms
        myModem.setSMSMode(1);//send as text
        myModem.flushInput();//clear reply in input stream
        myModem.sendSMS("99999999","sending as a text");

        //close connection

        Thread.sleep(5000);//just to relax sim card for a while =)no need if using independently
        myModem=new GSMModem("COM2",CONST.CONNECT_BAUD_9600);
        //show sms on sim
        LinkedList ll=myModem.showAllSMS();
        if(ll.size()==0) System.out.println("No msgs");
        for(int i=0;i<ll.size();i++)

         //how to delete<br>
         //close connection
    }catch(Exception e) {

You can generate JavaDocs using the source or view online.

Whats still missing/bugs:
  • PDU Format: Cant handle PDU format, uses text only (AT+CMGF=1)
  • HEX:Some bug in converting GSM 7 Bit to ASCII - does not do correctly for the funny characters, pls send me a corrected version if you figure it out.
Licensed as GPL, I'd appreciate if you send to me any extensions you write using this package.

No comments: