| 
 | MIDP3.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface SocketConnection
This interface defines the socket stream connection.
 A socket is accessed using a generic connection string with an explicit host
 and port number. The host may be specified as a fully qualified host name or
 IPv4 or IPv6 number. e.g. socket://host.com:79 defines a target socket
 on the host.com system at port 79.
 
Note that [RFC1900] recommends the use of names rather than IP numbers for best results in the event of IP number reassignment.
 Every StreamConnection provides a Connection
 object as well as an InputStream and OutputStream
 to handle the I/O associated with the connection. Each of these interfaces
 has its own close() method. For systems that support duplex
 communication over the socket connection, closing of the input or output
 stream SHOULD shutdown just that side of the connection. e.g. closing the
 InputStream will permit the OutputStream to
 continue sending data.
 
 Once the input or output stream has been closed, it can only be reopened with
 a call to Connector.open(). The application will receive an
 IOException if an attempt is made to reopen the stream.
 
 The URI must conform to the BNF syntax specified below. If the URI does not
 conform to this syntax, an IllegalArgumentException is thrown.
 
| <socket_connection_string> | ::= "socket://"<hostport> | 
| <hostport> | ::= host ":" port | 
| <host> | ::= host name or IP address (omitted for inbound connections, See ServerSocketConnection) | 
| <port> | ::= numeric port number | 
 The following examples show how a SocketConnection would be
 used to access a sample loopback program.
 
 SocketConnection sc = (SocketConnection)
 Connector.open("socket://host.com:79");
 sc.setSocketOption(SocketConnection.LINGER, 5);
 InputStream is = sc.openInputStream(); OutputStream os =
 sc.openOutputStream();
 os.write("\r\n".getBytes()); int ch = 0; while(ch != -1) { ch = is.read(); }
 is.close(); os.close(); sc.close();
 
| Field Summary | |
|---|---|
| static byte | DELAYSocket option for the small buffer writing delay (0). | 
| static byte | KEEPALIVESocket option for the keep alive feature (2). | 
| static byte | LINGERSocket option for the linger time to wait in seconds before closing a connection with pending data output (1). | 
| static byte | RCVBUFSocket option for the size of the receiving buffer (3). | 
| static byte | SNDBUFSocket option for the size of the sending buffer (4). | 
| Method Summary | |
|---|---|
|  java.lang.String | getAddress()Gets the remote address to which the socket is bound. | 
|  java.lang.String | getLocalAddress()Gets the local address to which the socket is bound. | 
|  int | getLocalPort()Returns the local port to which this socket is bound. | 
|  int | getPort()Returns the remote port to which this socket is bound. | 
|  int | getSocketOption(byte option)Get a socket option for the connection. | 
|  void | setSocketOption(byte option,
                int value)Set a socket option for the connection. | 
| Methods inherited from interface javax.microedition.io.InputConnection | 
|---|
| openDataInputStream, openInputStream | 
| Methods inherited from interface javax.microedition.io.Connection | 
|---|
| close | 
| Methods inherited from interface javax.microedition.io.OutputConnection | 
|---|
| openDataOutputStream, openOutputStream | 
| Methods inherited from interface javax.microedition.io.Connection | 
|---|
| close | 
| Field Detail | 
|---|
static final byte DELAY
static final byte LINGER
static final byte KEEPALIVE
static final byte RCVBUF
static final byte SNDBUF
| Method Detail | 
|---|
void setSocketOption(byte option,
                     int value)
                     throws java.lang.IllegalArgumentException,
                            java.io.IOException
Options inform the low level networking code about intended usage patterns that the application will use in dealing with the socket connection.
 Calling setSocketOption to assign buffer sizes is a hint
 to the platform of the sizes to set the underlying network I/O buffers.
 Calling getSocketOption can be used to see what sizes the
 system is using. The system MAY adjust the buffer sizes to account for
 better throughput available from Maximum Transmission Unit (MTU) and
 Maximum Segment Size (MSS) data available from current network
 information.
 
option - socket option identifier (KEEPALIVE, LINGER, SNDBUF, RCVBUF,
            or DELAY)value - numeric value for specified option
java.lang.IllegalArgumentException - if the value is not valid (e.g. negative value) or if the
                option identifier is not valid
java.io.IOException - if the connection was closedgetSocketOption(byte)
int getSocketOption(byte option)
                    throws java.lang.IllegalArgumentException,
                           java.io.IOException
option - socket option identifier (KEEPALIVE, LINGER, SNDBUF, RCVBUF,
            or DELAY)
java.lang.IllegalArgumentException - if the option identifier is not valid
java.io.IOException - if the connection was closedsetSocketOption(byte, int)
java.lang.String getLocalAddress()
                                 throws java.io.IOException
 Gets the local address to which the socket is bound. The address MUST be
 returned in the format of the requested IP version. The required IP version
 is specified by the MIDlet with MIDlet-Required-IP-Version
 manifest attribute. If the attribute is not specified, the implementation
 MAY decide the format in which the local address is returned.
 
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 reassignment.
 The local hostname (if available) can be accessed from
  System.getProperty("microedition.hostname")
 
java.io.IOException - if the connection was closed.ServerSocketConnection
int getLocalPort()
                 throws java.io.IOException
java.io.IOException - if the connection was closed.ServerSocketConnection
java.lang.String getAddress()
                            throws java.io.IOException
java.io.IOException - if the connection was closed.
int getPort()
            throws java.io.IOException
java.io.IOException - if the connection was closed.| 
 | MIDP3.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||