Wireless Messaging API

WMA

SMS Connection

SMS Client

Send a message by


      String address = "sms://+1234567:5432";
      String msg = "Hello";
      MessageConnection smsconn = 
             (MessageConnection) Connector.open(address);
      TextMessage txtmessage = (TextMessage)smsconn.newMessage(
                MessageConnection.TEXT_MESSAGE);
      txtmessage.setPayloadText(msg);
      smsconn.send(txtmessage)

SMS Server


try {
    String addr =  "sms://:5432";
    MessageConnection conn = (MessageConnection) Connector.open(addr);
    Message msg = null;
    while (someExitCondition) {
        // wait for incoming messages
        msg = conn.receive(); // received a message
        if (msg instanceof TextMessage) {
            TextMessage tmsg = (TextMessage) msg;
            String receivedText = tmsg.getPayloadText();
            // respond with the same text with  Received:
            // inserted in the beginning
            tmsg.setPayloadText("Received: " + receivedText);
            // Note that the recipient address in the message is
            // already correct as we are reusing the same object
            conn.send(tmsg);
        } else {
            // Received message was not a text message, but e.g. binary ...
        }
    }
} catch (Exception e) {
    ...
}

Emulator phone numbers

Complete client

Complete server

Send and receive

Send and receive client

Receive and send server


Jan Newmarch (http://jan.newmarch.name)
jan@newmarch.name
Last modified: Tue Apr 27 12:28:36 EST 2004
Copyright ©Jan Newmarch