10

JSR 120 – Wireless Messaging API

byte[] newBin = createBinary(msgLength);

binMsg.setPayloadData(newBin);

int num = connClient.numberOfSegments(binMsg);

Setting of MessageListener and receiving of notifications about incoming messages:

public class JSR120Sample1 extends MIDlet implements CommandListener {

JSR120Sample1Listener listener = new JSR120Sample1Listener();

// open connection

messageConnection = (MessageConnection)Connector.open("sms://:9532");

//create message to send

listener.run();

//set payload for the message to send

//set address for the message to send messageToSend.setAddress("sms://+18473297274:9532");

//send message (via invocation of ‘send’ method)

//set address for the message to receive receivedMessage.setAddress("sms://:9532");

//receive message (via invocation of ‘receive’ method)

class JSR120Sample1Listener implements MessageListener, Runnable {

private int messages = 0;

public void notifyIncomingMessage(MessageConnection connection) {

System.out.println("Notification about incoming message arrived");

messages++;

}

public void run() { try { messageConnection.setMessageListener(listener); } catch (IOException e) {

result = FAIL;

System.out.println("FAILED: exception while setting listener:

47

Page 47
Image 47
Motorola C381P technical manual JSR 120 Wireless Messaging API