Methods Summary |
---|
private native int | accept()Accepts a TCP connection socket handle to a client,
accesses the handle field.
|
public synchronized StreamConnection | acceptAndOpen()Returns a connection that represents a server side
socket connection.
Polling the native code is done here to allow for simple
asynchronous native code to be written. Not all implementations
work this way (they block in the native code) but the same
Java code works for both.
com.sun.midp.io.j2me.socket.Protocol con;
ensureOpen();
while (true) {
int handle = accept();
if (handle >= 0) {
con = new com.sun.midp.io.j2me.socket.Protocol();
con.open(handle);
break;
}
/* Wait a while for I/O to become ready */
GeneralBase.iowait();
}
return con;
|
public void | close()Closes the connection, accesses the handle field.
if (connectionOpen) {
close0();
connectionOpen = false;
}
|
public native void | close0()Closes the connection, accesses the handle field.
|
void | ensureOpen()Checks if the connection is open.
if (!connectionOpen) {
throw new IOException("Connection closed");
}
|
private native void | finalize()Native finalizer
|
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")
ensureOpen();
return getLocalAddress0();
|
private native java.lang.String | getLocalAddress0()Gets the requested printable IP number.
|
public int | getLocalPort()Returns the local port to which this socket is bound.
ensureOpen();
return getLocalPort0();
|
private native int | getLocalPort0()Returns the local port to which this socket is bound.
|
public void | open(int port)Opens a port to listen on.
Scheduler scheduler = Scheduler.getScheduler();
MIDletSuite midletSuite = scheduler.getMIDletSuite();
String root = midletSuite.getStorageName();
byte[] asciiStorage = Util.toCString(root);
open0(port > 0 ? port : 0, asciiStorage);
connectionOpen = true;
port = getLocalPort();
// check permission after the open so we can get the assigned port
try {
// When asking permission use Internet protocol name.
midletSuite.checkForPermission(Permissions.TCP_SERVER,
"TCP://:" + port);
} catch (SecurityException e) {
close();
throw e;
} catch (InterruptedException ie) {
throw new InterruptedIOException(
"Interrupted while trying to ask the user permission");
}
registerCleanup();
|
public native void | open0(int port, byte[] storage)Opens a native socket and put its handle in the handle field.
Called by socket Protocol class after it parses a given URL and finds
no host.
|
private native void | registerCleanup()Registers with the native cleanup code, accesses the handle field.
|