Java Reference
In-Depth Information
CHAPTER 12
Accessing Remote Data
on the Network
S un Microsystems' early success was as a manufacturer of high-performance computing
platforms for scientific and engineering purposes. A key feature of most workstations—
including Sun's hardware—was support for networking. Embodied in the motto associated
with Sun, “The Network Is the Computer,” this commitment to networking continues to
this day with the robust network solutions available to and crafted using the Java platform.
Java ME is no exception; it was designed from the ground up as a platform that interacts
with other computers on the network.
In this chapter, I talk about what is perhaps one of the most important contributions
Java ME has made to the Java platform: the Generic Connection Framework (GCF). This
framework provides a unified API for interacting with systems on the network using dis-
parate protocols, and it has been extended to encompass file operations (see Chapter 7),
wireless communications using SMS (see Chapter 14), and contactless communications
(see Chapter 15). First, I explain what the GCF is and what it provides to you as an applica-
tion developer. Next, I show you how to use the GCF to perform low-level communications
on today's IP network using TCP and UDP. The bulk of the chapter, however, shows you how
to use the GCF to access remote resources on the Internet using HTTP, an important facet
of nearly every Java ME networked application. I close with a word on how the Java ME
privilege model may affect your application.
Introducing the Generic Connection Framework
I/O and communication in the Java SE world is a wild ride: you find sockets, files, and con-
nection classes (derived from URLConnection ) residing in the java.net and java.io packages.
Arguably powerful, to its detriment the Java SE framework for I/O requires you to have a
command of a relatively large number of interfaces, many with dissimilar semantics. This
turns out to be equally unwieldy for mobile devices as well; these deep and sophisticated
class hierarchies don't scale well to mobile devices, especially those running the first
releases of Java ME. Consequently, with the introduction of the first CLDC, Sun introduced
the GCF, a straightforward hierarchy of interfaces and classes for managing connections
293
 
Search WWH ::




Custom Search