Java Reference
In-Depth Information
Chapter 6. Networking: The Generic Connection
Framework
IN THIS CHAPTER
Creating a Connection—The Connector Class
Connection Types
GCF Examples
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
Sample String Parameter for
Connector.open()
Protocol
Connection Type
HTTP
http://java.sun.com
H ttpConnection
Sockets
socket://time-a.nist.gov:13
S treamConnection
ServerSockets serversocket://:4444
S treamConnectionNotifier
Serial
comm:0;baudrate=2400;
C ommConnection
Datagrams
datagram://127.0.0.1
D atagramConnection
 
 
 
Search WWH ::




Custom Search