Download
khanh le n.
Skip this Video
Loading SlideShow in 5 Seconds..
J2ME Messaging PowerPoint Presentation
Download Presentation
J2ME Messaging

J2ME Messaging

167 Vues Download Presentation
Télécharger la présentation

J2ME Messaging

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Khanh Le J2ME Messaging

  2. Objective • The objective of wireless messaging is to extend the networking and I/O capabilities of J2ME applications to send and receive messages using the messaging services on GSM networks, like Short Message Service (SMS) and Cell Broadcast Service (CBS).

  3. The Wireless Messaging System - an overview • The notion of wireless messaging provides a whole new vista to J2ME. J2ME applications powered by wireless messaging have a platform-independent access to wireless communication resources like Short Message Service (SMS) and Cell Broadcast Service (CBS) for Global System for Mobile Communication (GSM) Networks, a mobile telephony system permitting inter-country communication. • Before proceeding with the details on how J2ME Wireless Messaging works, I will discuss, in short, the SMS and CBS messaging systems in a GSM Network.

  4. GSM Short Message Service (SMS) • SMS is the transmission of short text messages to and from a mobile phone, fax machine, and/or IP address in a GSM network. • Messages must be no longer than 160 alphanumeric characters and contain no images or graphics. • The main features of this service are speed, cheap rates, and the guarantee that the message will reach the target person, even if he is out of radio coverage or his phone is turned off.

  5. GSM Short Message Service (SMS)

  6. GSM cell broadcast service • The GSM cell broadcast service allows messages to be sent to every Mobile Station (MS), such as a mobile phone, fax machine, and/or IP address currently in a particular cell. • Cell broadcast messages are repeated at intervals over a period of time, which allows an MS to receive the message even if entering the cell after the first transmission. • The data can be sent either as binary data or ASCII text up to 15 pages in length, with a page being up to 93 characters in length; the test set only provides support for ASCII messages. • Cell broadcast messages are classified by topic and allocated a channel number, message code, update number, and language • While SMS is a one-to-one and one-to-few messaging system, CBS provides one-to-many messaging within a certain geographical area.

  7. The wireless messaging system • This system can be viewed as a 3-tiered architecture, consisting of the Interface Layer, Implementation Layer and Transport Layer. • The Interface Layer constitutes a generic set of messaging interfaces, independent of any messaging protocol. • The Implementation Layer contains classes which implement each Interface Layer to access wireless messaging like SMS or CBS functionalities on a GSM mobile device.. • The Transport Layer contains classes that are the actual implementation of protocols that carry messages to the mobile device.

  8. The wireless messaging system

  9. The Generic Messaging API, javax.wireless.messaging • This API defines all the interfaces for sending and receiving wireless messages. Following is a list of interfaces: • Message. This provides the basic definition of a message, which acts as a container holding address, payload, and flags to send and block for a message. It is a superinterface to TextMessage, a message object with a text payload attribute, and a BinaryMessage, a message object with a binary payload attribute.

  10. The Generic Messaging API, javax.wireless.messaging • MessageConnection. This provides the basic functionality of receiving and sending messages. It contains a method for sending and receiving messages, a factory method for creating new Message objects, and a method that calculates the number of segments of the underlying protocol that are needed to send a specified Message object. • This class is instantiated by a call to Connector.open().

  11. The Generic Messaging API, javax.wireless.messaging • In a client mode connection, messages can only be sent. A client mode connection is created by passing a string identifying a destination address to the Connector.open() method. This method returns a MessageConnection object. • clientConn = (MessageConnection)Connector.open("sms:// +18643630999:5000"); • In a server mode connection, messages can be sent or received. A server mode connection is created by passing a string that identifies an end point (protocol dependent identifier, for example, a port number) on the local host to the Connector.open() method. • serverConn = (MessageConnection)Connector.open("sms://:5000"); • MessageListener. This provides a basic mechanism to notify the MIDlet application of an incoming message. It allows a MIDlet to receive a callback when new messages are available to be read.

  12. The Short Message Service API • The com.sun.midp.io.j2me.sms package provides an API for the Short Message Service Messaging system and allows MIDlet to access SMS functionality on a GSM mobile device. • The main components of the package -- MessageObject and Protocol -- support the sending and receiving of SMS messages.

  13. The Short Message Service API • MessageObject. MessageObject is the implementation of a SMS message. In the Implementation layer, the javax.wireless.messaging.Message interface is implemented as a buffer. The MessageObject handles the creation of message buffers and the input/output operations out of a buffer. Furthermore, it has two subclasses -- TextObject and BinaryObject. These classes implement a SMS message with a payload, whether text or binary. • Protocol. This implements the message connection to a low-level Transport mechanism required to transmit a SMS message. In the process, it checks for all runtime configuration parameters and handles exceptions related to invalid URL syntax, security violations, I/O violations, and illegal arguments. Protocol also handles the sending and receiving of messages using a datagram or serial port connection.

  14. The Cell Broadcast Messaging API • The com.sun.midp.io.j2me.cbs package provides an API for the Cell Broadcast Messaging system and allows MIDLlet to access CBS functionality on a GSM mobile device. • The main component of the package, com.sun.midp.io.j2me.cbs.Protocol, supports the receipt of a CBS Message. • The CBS differs from SMS in that: • The URL Connection string does not support a designated host, and • It is meant for an inbound-only protocol. A MIDlet having CBS capability can receive messages, but cannot send them.

  15. A J2ME messaging application • In this section, I will show an example of a WMAServer that waits for incoming SMS messages and then displays them on a phone screen. The javax.microedition.lcdui package provides a set of features for implementation of user interfaces for the applications. • The WMAServer MIDlet creates a server mode connection by passing a string that identifies an end point (protocol-dependent identifier -- like a port number, for example ) on the local host to the Connector.open() method. • In order to get notified of an incoming message, the MIDlet registers a MessageListener object at the MessageConnection instance, serverConn. • serverConn.setMessageListener(MessageListener ml);

  16. A J2ME messaging application • It also implements notifyIncomingMessage() in the MessageListener interface. When an incoming message arrives at the MessageConnection, the notifyIncomingMessage() method is called. The application must retrieve the message using the receive() method of the MessageConnection. • The WMAServer application reads the payload data from the incoming message, whether text or binary, and stores it in a string object to be displayed later.

  17. A J2ME messaging application public void notifyIncomingMessage(MessageConnection conn) { Message msg = null; // Try reading (maybe block for) a message try { msg = conn.receive(); } catch (Exception e) { // Handle reading errors System.out.println("processMessage.receive " + e); } // Process the received message if (msg instanceof TextMessage) { TextMessage tmsg = (TextMessage)msg; msgReceived = tmsg.getPayloadText(); } else { // process received message if (msg instanceof BinaryMessage) { BinaryMessage bmsg = (BinaryMessage)msg; byte[] data = bmsg.getPayloadData(); // Handle the binary message... msgReceived = data.toString(); } }

  18. A J2ME messaging application • The application provides a destroyApp() method when the connection resources and associated listener objects must be released. public void destroyApp(boolean unconditional) { try { if (serverConn != null) { serverConn.setMessageListener(null); serverConn.close(); } } catch (IOException e) { // Handle the exception... e.printStacktrace(); }

  19. A J2ME messaging application • Next is an example of a WMA client that sends a SMS message to a GSM mobile phone. The WMA Client can only send messages. It creates a MessageConnection by passing a string identifying a destination address (which is a valid mobile number) to the Connector.open() method. try { clientConn = (MessageConnection)Connector.open("sms:// +18643630999:5000"); } catch (IOException ioExc) { System.out.println("Client connection could not be obtained"); ioExc.printStackTrace(); }

  20. A J2ME messaging application • It then creates a valid TextMessage object by setting the payload and destination address and sends the message through the MessageConnection. TextMessage tmsg = (TextMessage)clientConn.newMessage (MessageConnection.TEXT_MESSAGE);tmsg.setAddress("sms://18643630999:5000");tmsg.setPayloadText(msgToSend); clientConn.send(tmsg);