Java Reference
In-Depth Information
The GCF hierarchy is a tightly woven collection of interfaces with a sprinkling of classes:
The Connector class : Responsible for operating as a factory of Connection objects.
The Connection interface : Represents a generic connection between two entities.
The Connection interface defines the close method, which is responsible for closing
a connection.
The DatagramConnection interface : Defines the actions you can take on a datagram-
oriented connection such as UDP.
The StreamConnection interface : Defines the actions you can take on a stream-
oriented connection such as TCP. StreamConnection instances are bidirectional,
consisting of an InputConnection (from which you read data) and an
OutputConnection (to which you write data).
The StreamConnectionNotifier interface : Defines the actions you can take when
listening for a new StreamConnection .
The ContentConnection interface : Supports the passing of content encoded through
a well-known codec.
The Datagram interface : Defines an abstract interface for a single datagram.
Datagram s are bidirectional, implementing this functionality by extending the
DataInput and DataOutput interfaces.
The IOException class : Signals generic communications errors such as network fail-
ures, and the ConnectionNotFoundException , which is thrown by Connector class
methods when you attempt to create a connection that the platform cannot
resolve. (This IOException class isn't formally part of the GCF.)
When you use the GCF, you follow these steps:
1. Create a URL describing the kind of socket you'd like to open and detailing the
address and name of the resource to which you want to connect.
2. Invoke the Connector.open class method, passing the URL you constructed to
receive an instance of a specific Connection subclass.
3. Use the concrete Connection subclass methods for the kind of connection
Connector.open returned to you to work with the connection.
The pseudocode in Listing 12-1 demonstrates this pattern, opening an HTTP con-
nection to the server www.nowhere.com and obtaining an InputStream from which to read.
 
Search WWH ::




Custom Search