Java Reference
In-Depth Information
to the server, encrypted with the server's public key. The server and the client both derive a
session key from this secret value, which is used to encrypt all subsequent traffic sent between
the client and server.
The generic connection framework makes it very easy to obtain HTTPS connections.
All you have to do is construct an HTTPS connection string. So instead of this:
HttpConnection hc = (HttpConnection)
Connector.open("http://www.cert.org/");
you would do this:
HttpsConnection hc = (HttpsConnection)
Connector.open("https://www.cert.org/");
It's really that simple. HttpsConnection represents HTTP carried over some secure
transport.
HttpsConnection is an extension of HttpConnection ; it adds a getPort() method so that you
can find out the server's port number. The default port for HTTPS is 443. More importantly,
HttpsConnection has a getSecurityInfo() method that returns information about the secure
connection. The new SecurityInfo interface encapsulates information about the cipher suite
in use, the name and version of the secure protocol, and the server's certificate. The certificate
is an implementation of javax.microedition.pki.Certificate and includes standard informa-
tion like the subject, signer, signature algorithm, and validity dates of the certificate.
The following example shows how you can retrieve the subject of a server certificate from
an HTTPS connection:
String url = "https://www.cert.org/";
HttpsConnection hc = (HttpsConnection)Connector.open(url);
SecurityInfo si = hc.getSecurityInfo();
Certificate c = si.getServerCertificate();
String subject = c.getSubject();
Using Datagram Connections
In this section, we'll briefly describe datagram connections. Although support for datagrams is
not mandated by the MIDP specification, certain device implementations may choose to
support datagram connections. Unlike stream-oriented connections, datagram connections
are connectionless . This means that you can fire packets of data around the network, but you
have no guarantee that they will reach their destination in the right order, or that they will even
arrive at all.
Datagram communications is based on two interfaces in the javax.microedition.io
package, DatagramConnection and Datagram . Figure 10-4 shows the methods in
DatagramConnection .
The first step is to use the generic connection framework to obtain a DatagramConnection
something like this:
String url = "datagram://jonathanknudsen.com:7999";
DatagramConnection dc = (DatagramConnection)Connector.open(url);
Search WWH ::




Custom Search