Methods Summary |
---|
public void | close()Close the connection to the target.
try {
sslConnection.close();
} finally {
tcpConnection.close();
}
|
public java.lang.String | getAddress()Gets the remote address to which the socket is bound.
The address can be either the remote host name or the IP
address(if available).
return tcpConnection.getAddress();
|
public java.lang.String | getLocalAddress()Gets the local address to which the socket is bound.
The host address(IP number) that can be used to connect to this
end of the socket connection from an external system.
Since IP addresses may be dynamically assigned a remote application
will need to be robust in the face of IP number reasssignment.
The local hostname (if available) can be accessed from
System.getProperty("microedition.hostname")
return tcpConnection.getLocalAddress();
|
public int | getLocalPort()Returns the local port to which this socket is bound.
return tcpConnection.getLocalPort();
|
public int | getPort()Returns the remote port to which this socket is bound.
return tcpConnection.getPort();
|
public SecurityInfo | getSecurityInfo()Return the security information associated with this connection.
If the connection is still in Setup state then
the connection is initiated to establish the secure connection
to the server. The method returns when the connection is
established and the Certificate supplied by the
server has been validated.
The SecurityInfo is only returned if the
connection has been successfully made to the server.
return sslConnection.getSecurityInfo();
|
public int | getSocketOption(byte option)Get a socket option for the connection.
return tcpConnection.getSocketOption(option);
|
public static void | initSecurityToken(SecurityToken token)Initializes the security token for this class, so it can
perform actions that a normal MIDlet Suite cannot.
if (classSecurityToken != null) {
return;
}
classSecurityToken = token;
|
public java.io.DataInputStream | openDataInputStream()Open and return a data input stream for a connection.
return sslConnection.openDataInputStream();
|
public java.io.DataOutputStream | openDataOutputStream()Open and return a data output stream for a connection.
return sslConnection.openDataOutputStream();
|
public java.io.InputStream | openInputStream()Returns an input stream.
return sslConnection.openInputStream();
|
public java.io.OutputStream | openOutputStream()Returns an output stream.
return sslConnection.openOutputStream();
|
public Connection | openPrim(java.lang.String name, int mode, boolean timeouts)Connect to the underlying secure socket transport.
Scheduler scheduler = Scheduler.getScheduler();
MIDletSuite midletSuite = scheduler.getMIDletSuite();
HttpUrl url;
OutputStream tcpOutputStream;
InputStream tcpInputStream;
try {
midletSuite.checkForPermission(Permissions.SSL, "ssl:" + name);
} catch (InterruptedException ie) {
throw new InterruptedIOException(
"Interrupted while trying to ask the user permission");
}
if (name.charAt(0) != '/" || name.charAt(1) != '/") {
throw new IllegalArgumentException(
"Protocol must start with \"//\"");
}
url = new HttpUrl("ssl", name); // parse name into host and port
/*
* Since we reused the HttpUrl parser, we must make sure that
* there was nothing past the authority in the URL.
*/
if (url.path != null || url.query != null || url.fragment != null) {
throw new IllegalArgumentException("Malformed address");
}
tcpConnection = new com.sun.midp.io.j2me.socket.Protocol();
tcpConnection.openPrim(classSecurityToken, "//" + url.authority);
try {
tcpOutputStream = tcpConnection.openOutputStream();
try {
tcpInputStream = tcpConnection.openInputStream();
/*
* Porting note: This would be the place to connect to a
* SOCKS proxy if desired.
*/
try {
/*
* To save memory for applications the do not use SSL,
* the public keys of the certificate authorities may not
* have been loaded yet.
*/
WebPublicKeyStore.loadCertificateAuthorities();
// Get the SSLStreamConnection
sslConnection = new SSLStreamConnection(url.host, url.port,
tcpInputStream, tcpOutputStream);
} catch (IOException e) {
tcpInputStream.close();
throw e;
}
} catch (IOException e) {
tcpOutputStream.close();
throw e;
}
} catch (IOException e) {
tcpConnection.close();
throw e;
}
return this;
|
public void | setSocketOption(byte option, int value)Set a socket option for the connection.
Options inform the low level networking code about intended
usage patterns that the application will use in dealing with
the socket connection.
tcpConnection.setSocketOption(option, value);
|