Messaging in J2ME
Messaging applications that are capable of sending and receiving messages to and from mobile devices can be easily developed with the help of J2ME. Thus J2ME provides the wireless messaging API to facilitate the development of wireless messaging applications. The wireless messaging API is an optional package availabe in J2ME which can be used for developing messaging services on mobile phones. The wireless messaging API specification defines APIs for sending and receiving all types of messages such as text, binary,CBS and multipart. Different types of interfaces are provided by WMA to create, send and receive the messages. WMA is also an optional API mentioned in JSR 120 and JSR 205 specifications. A wide range of devices support the Generic Connection Framework(GCF) defined in CLDC. The primary function of GCF is to provide classes and interfaces to connect the devices that take part in the messaging process. The javax.wireless.messaging provides implementation of all the functions required to develop a messaging application.
Messaging applications that are capable of sending and receiving messages to and from mobile devices can be easily developed with the help of J2ME. Thus J2ME provides the wireless messaging API to facilitate the development of wireless messaging applications. The wireless messaging API is an optional package availabe in J2ME which can be used for developing messaging services on mobile phones. The wireless messaging API specification defines APIs for sending and receiving all types of messages such as text, binary,CBS and multipart. Different types of interfaces are provided by WMA to create, send and receive the messages. WMA is also an optional API mentioned in JSR 120 and JSR 205 specifications. A wide range of devices support the Generic Connection Framework(GCF) defined in CLDC. The primary function of GCF is to provide classes and interfaces to connect the devices that take part in the messaging process. The javax.wireless.messaging provides implementation of all the functions required to develop a messaging application.
The following two packages are available in WMA.
- javax.microedition.io.
- javax.wireless.messaging
The javax.microedition.io Package
This package provides networking support, so that mobile devices can connect with each other in a networked environment. A highly sophisticated protocol has been defined to facilitate the exchange of data. The main objective of this package is to provide protocol or generic independent mobile devices. An important point to be noted is that GCF is contained in javax.microedition.io package and facilitates the connection procedure. This approach of providing the connectivity is known as generic as a common API is used for all the basic connection types. This can be achieved with the help of an interface hierarchy which is extensible and a URL. This URL can be used to identify the location and methods to access the resource. Also, the address portion of the URL can be used to identify the handset and the application. An example of client connection URL is shown below.
(MessageConnection)Connector.open ("sms://+999...);
The format of the URL can be represented as follows.
protocol://recipient:port
In the above URL, the protocol or scheme helps to identify how the connection is made and the various types of information that is transferred through the protocol. The reciepient can be either the receiver's phone number or e-mail address.
This package provides networking support, so that mobile devices can connect with each other in a networked environment. A highly sophisticated protocol has been defined to facilitate the exchange of data. The main objective of this package is to provide protocol or generic independent mobile devices. An important point to be noted is that GCF is contained in javax.microedition.io package and facilitates the connection procedure. This approach of providing the connectivity is known as generic as a common API is used for all the basic connection types. This can be achieved with the help of an interface hierarchy which is extensible and a URL. This URL can be used to identify the location and methods to access the resource. Also, the address portion of the URL can be used to identify the handset and the application. An example of client connection URL is shown below.
(MessageConnection)Connector.open ("sms://+999...);
The format of the URL can be represented as follows.
protocol://recipient:port
In the above URL, the protocol or scheme helps to identify how the connection is made and the various types of information that is transferred through the protocol. The reciepient can be either the receiver's phone number or e-mail address.
The javax.wireless.messaging Package
This package contains APIs that help the applications to send and receive wireless messages. It contains a base interface known as Message that represents the communicated message. It also has several sub-interfaces such as BinaryMessage, TextMessage andMultipartMessage that corresponds to binary, text and multipart messages respectivly. Additionally an interface known as MessageConnection interface which is a sub-interface of the GCF's connection interface is also defined. Another interface known as MessageListener interface is used for asynchronously listening the messages that is being received. Now there are different format of messages such as binary, text and multipart messages. Each of these message types are created in a manner that is different from each other.
A small example of creating a binary message is shown below.
This package contains APIs that help the applications to send and receive wireless messages. It contains a base interface known as Message that represents the communicated message. It also has several sub-interfaces such as BinaryMessage, TextMessage andMultipartMessage that corresponds to binary, text and multipart messages respectivly. Additionally an interface known as MessageConnection interface which is a sub-interface of the GCF's connection interface is also defined. Another interface known as MessageListener interface is used for asynchronously listening the messages that is being received. Now there are different format of messages such as binary, text and multipart messages. Each of these message types are created in a manner that is different from each other.
A small example of creating a binary message is shown below.
byte[] loadedmsg = null;
String destination = "123456";
String port = "1234";
String adress = "sms://" + destination + ":" + port;
MessageConnection mycon = null;
try
{
mycon = (MessageConnection) Connector.open(adress);
BinaryMessage mymessage = (BinaryMessage)
mycon.newMessage(MessageConnection.BINARY_MESSAGE);
mymessage.setPayloadData(loadmsg);
mycon.close();
}
catch(Exception ex1)
{
}
Now the code for Sending a binary message is shown below.byte[] loadedmsg = null;
String destination = "123456";
String port = "1234";
String adress = "sms://" + destination + ":" + port;
MessageConnection mycon = null;
try
{
mycon = (MessageConnection) Connector.open(adress);
BinaryMessage mymessage = (BinaryMessage)
mycon.newMessage(MessageConnection.BINARY_MESSAGE);
mymessage.setPayloadData(loadmsg);
mycon.send(mymessage);
mycon.close();
}
catch(Exception ex1)
{
}
Finally the code for receiving a binary message is as shown belowbyte[] loaedmsg = null;
tring destination = "123456";
String port = "1234";
String adress = 'sms://" + destination + ":" + port;
MessageConnection mycon = null;
mycon = (MessageConnection) Connector.open(adress);
BinaryMessage mymessage = (BinaryMessage)mycon.receive();
mycon.close();
}
catch(Exception ex1)
{
}

No comments:
Post a Comment