Package com.objectxp.msg

This Package provides the classes necessary to send and receive GSM Short Messages (SMS).

See: Description

Package com.objectxp.msg Description

This Package provides the classes necessary to send and receive GSM Short Messages (SMS).

jSMS currently supports the following transport facilities:

jSMS supports text messages (using the 7-bit and UCS2 alphabet) as well as binary messages (8-bit) and Nokia SmartMessages (Business Cards, Calendar Entries, Picture Messages, Operator Logos and Ringtones).

The jSMS API has been designed with a modular architecture in focus. This allows an easy integration of other SMS capable facilities.

The following example code demonstrates how to send a Short Message using a SMS-capable GSM-Device:

  package com.mydomain.sms;

  import java.io.File;
  import com.objectxp.msg.*;

  public class SendSMS
  {
    public static void main(String args[])
    {
      File configuration = new File("/path/to/my/jsms.properties");
      SmsService service = new GsmSmsService();

      try {
        service.init(configuration);
      } catch( Exception ex ) {
        System.err.println("Unable to initialize service: "+ex.getMessage());
        System.exit(0);
      }
      
      SmsMessage msg = new SmsMessage(service);
      msg.setRecipient("+411123456");
      msg.setMessage("Hello World");
      
      try {
        service.connect();
        service.sendMessage(msg);
        System.out.println("Message sent!");   
      } catch( MessageException ex ) {
        System.err.println("Error while sending the Message: "+ex.getMessage());
      }
    }
  }

The next example shows you how to receive Short Messages using CIMD2 over TCP/IP:

  package com.mydomain.sms;
  
  import com.objectxp.msg.*;
  import java.io.File;
  
  public class ReceiveSMS
  {
    public static void main(String[] args)
    {
      File configuration = new File("/path/to/my/jsms.properties");
      SmsService service = new Cimd2SmsService();
    
      try {
        service.init(configuration);
      } catch( Exception ex ) {
        System.err.println("Unable to initialize service: "+ex.getMessage());
        System.exit(0);
      }
      
      // Register a message event handler
      service.addMessageEventListener( new MessageEventListener() {
        public void handleMessageEvent(MessageEvent event)
        {
          if ( event.getType() == MessageEvent.MESSAGE_RECEIVED )
          {
              Message msg = event.getMessage();
              System.out.println("Message from "+msg.getSender()+": "+msg.getMessage());
          }
        }
      });
      
      try {
        // Connect to the CIMD2 SMS Center
        service.connect();
      
        // Start receiving messages
        service.startReceiving();
        
        System.out.print("Press any key to stop receiving messages");
        System.in.read();
        
        // Disconnect 
        service.disconnect();
        
      } catch( Exception ex ) {
        System.err.println("Exception occured while receiving SMS: "+ex.getMessage());
        System.exit(0);
      }
    }
  }

object XP, Inc. © 2000-2013. All rights reserved object XP