【用函数判断pȝ是Big Endianq是Little Endian?/font>
Generic Connections
In the CLDC Generic Connection framework, all connections are created using
the open
static method from the Connector
class. If
successful, this method returns an object that implements one of the generic
connection interfaces. Figure 1 shows how these interfaces form an is-a
hierarchy. The Connection
interface is the base interface such
that StreamConnectionNotifier
is a Connection
and
InputConnection
is a Connection
too.
Connection
interface is the most basic connection type. It
can only be opened and closed.InputConnection
interface represents a device from which
data can be
read. Its openInputStream
method returns an input stream for the
connection.
OuputConnection
interface represents a device to which data
can be
written. Its openOutputStream
method returns an output stream for
the connection.
StreamConnection
interface combines the input and output
connections.
ContentConnection
is a subinterface of
StreamConnection
. It
provides access to some of the basic meta data information provided by HTTP
connections.
StreamConnectionNotified
waits for a connection to be
established.
It returns a StreamConnection
on which a communication link has ben
established.
DatagramConnection
represents a datagram endpoint.
The open
method of the Connector
class has the
following syntax, where the String
parameter has the format
"protocol:address;parameters"
.
Here are a few examples:
HTTP Connection
Datagram Connection
Communicate with a Port
Open Files
In the setup state the following methods can be invoked:
setRequestMethod
setRequestProperty
For example, suppose you have this connection:
Then, you can set the request method to be of type POST
as follows:
And likewise, you can set some of the HTTP properties. For example, you
can set the User-Agent
as follows:
If there is a method that requires data to be sent or received from the server, there is a state transition from Setup to Connected. Examples of methods that cause the transition include:
And while the connection is open, some of these methods that may be invoked: