Chapter 6. Networking: The Generic Connection Framework

IN THIS CHAPTER

For the Java 2 Standard Edition, the classes for handling network connections are located in the java.net package. This package contains a lot of different classes. It includes at least one class for each type of connection, such as socket connections, HTTP connections, datagram connections, and server sockets. It also contains many support classes, for instance classes for handling URLs or decoding Internet addresses. In sum, the java.net package includes more than 20 classes, interfaces, and exception classes.

The huge amount of classes and interfaces that is needed to support network capabilities would be too much to be adopted for the Java 2 Micro Edition. Thus, the Connected Limited Device Configuration (CLDC) takes a different approach: Instead of providing one class for each protocol like J2SE, CLDC offers a uniform approach for handling connections, the so-called Generic Connection Framework (GCF). GCF contains only one generic Connector class. The Connector class takes a URI as input and returns a corresponding connection object, depending on the protocol parameter of the URI string. The protocol parameter of a URI is the part from the beginning of the string to the first colon. For example, for an HTTP connection, the protocol parameter is the leading http of an address such as http://java.sun.com. The general form of URI strings that are passed to the Connector class is as follows:

<protocol>://<address>;<parameters>

The syntax of the strings that are passed to the Connector.open() method needs to follow the Uniform Resource Indicator (URI) syntax that is defined in the IETF standard RFC2396. The complete RFC can be found under the following URI: http://www.ietf.org/rfc/rfc2396.txt.

Note

The CLDC itself specifies interfaces, classes, and exceptions of the GCF only. No implementations of any concrete connection type are provided at the configuration level.


Table 6.1 gives an illustrative overview of connection types that can be implemented by a particular J2ME profile such as the MID or PDA Profile. J2ME profiles might also include additional protocols that are not listed in Table 6.1.

Table 6.1. Example URLs for the Connector.open() Method of the Generic Connection Framework
Protocol Sample String Parameter for Connector.open() Connection Type
HTTP http://java.sun.com HttpConnection
Sockets socket://time-a.nist.gov:13 StreamConnection
ServerSockets serversocket://:4444 StreamConnectionNotifier
Serial comm:0;baudrate=2400; CommConnection
Datagrams datagram://127.0.0.1 DatagramConnection
File file://addesses.dat FileConnection
Bluetooth bluetooth://psm=1001StreamConnection

The only connection type that is guaranteed to be available in MIDP 1.0 is the HTTP protocol. PDAP adds specialized interfaces for access to serial ports and file systems. Whether a certain protocol is actually available depends on the device. For example, it does not make sense to support the comm protocol on devices without a serial port.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset