SunSPOT API V6.0


com.sun.squawk.io.j2me.socket
Class Protocol

java.lang.Object
  extended by com.sun.squawk.io.ConnectionBase
      extended by com.sun.squawk.io.j2me.socket.Protocol
All Implemented Interfaces:
Connection, InputConnection, OutputConnection, SocketConnection, StreamConnection

public class Protocol
extends ConnectionBase
implements SocketConnection

Support for socket connections on device. This allows a generic stream connection with an external host (on a TCP network). This must be used in conjunction with a SocketProxy on a host computer.

Author:
Martin Morissette

Field Summary
protected  int port
           
 
Fields inherited from interface javax.microedition.io.SocketConnection
DELAY, KEEPALIVE, LINGER, RCVBUF, SNDBUF
 
Constructor Summary
Protocol()
           
Protocol(SocketConnection connection)
           
 
Method Summary
 void close()
          Close the connection.
 String getAddress()
          Gets the remote address to which the socket is bound.
 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.
 Connection open(String protocol, String originalName, int mode, boolean timeouts)
          Open the connection
 InputStream openInputStream()
          Returns an input stream for this socket.
 OutputStream openOutputStream()
          Returns an output stream for this socket.
 void setSocketOption(byte option, int value)
          Set a socket option for the connection.
 
Methods inherited from class com.sun.squawk.io.ConnectionBase
openDataInputStream, openDataOutputStream
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.microedition.io.InputConnection
openDataInputStream
 
Methods inherited from interface javax.microedition.io.OutputConnection
openDataOutputStream
 

Field Detail

port

protected int port
Constructor Detail

Protocol

public Protocol()

Protocol

public Protocol(SocketConnection connection)
Method Detail

open

public Connection open(String protocol,
                       String originalName,
                       int mode,
                       boolean timeouts)
                throws IOException
Open the connection

Specified by:
open in class ConnectionBase
Parameters:
originalName - :
protocol - The URL protocol
mode - The access mode
timeouts - A flag to indicate that the caller wants timeout exceptions
Returns:
A new Connection object
Throws:
IOException
ConnectionNotFoundException - If the connection cannot be found.

openInputStream

public InputStream openInputStream()
                            throws IOException
Returns an input stream for this socket.

Specified by:
openInputStream in interface InputConnection
Overrides:
openInputStream in class ConnectionBase
Returns:
an input stream for reading bytes from this socket.
Throws:
IOException - if an I/O error occurs when creating the input stream.

openOutputStream

public OutputStream openOutputStream()
                              throws IOException
Returns an output stream for this socket.

Specified by:
openOutputStream in interface OutputConnection
Overrides:
openOutputStream in class ConnectionBase
Returns:
an output stream for writing bytes to this socket.
Throws:
IOException - if an I/O error occurs when creating the output stream.

close

public void close()
           throws IOException
Close the connection.

Specified by:
close in interface Connection
Overrides:
close in class ConnectionBase
Throws:
IOException - if an I/O error occurs when closing the connection.

getAddress

public String getAddress()
                  throws IOException
Description copied from interface: SocketConnection
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).

Specified by:
getAddress in interface SocketConnection
Returns:
the remote address to which the socket is bound.
Throws:
IOException - if the connection was closed.

getLocalAddress

public String getLocalAddress()
                       throws IOException
Description copied from interface: SocketConnection
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")

Specified by:
getLocalAddress in interface SocketConnection
Returns:
the local address to which the socket is bound.
Throws:
IOException - if the connection was closed.
See Also:
ServerSocketConnection

getLocalPort

public int getLocalPort()
                 throws IOException
Description copied from interface: SocketConnection
Returns the local port to which this socket is bound.

Specified by:
getLocalPort in interface SocketConnection
Returns:
the local port number to which this socket is connected.
Throws:
IOException - if the connection was closed.
See Also:
ServerSocketConnection

getPort

public int getPort()
            throws IOException
Description copied from interface: SocketConnection
Returns the remote port to which this socket is bound.

Specified by:
getPort in interface SocketConnection
Returns:
the remote port number to which this socket is connected.
Throws:
IOException - if the connection was closed.

getSocketOption

public int getSocketOption(byte option)
                    throws IOException
Description copied from interface: SocketConnection
Get a socket option for the connection.

Specified by:
getSocketOption in interface SocketConnection
Parameters:
option - socket option identifier (KEEPALIVE, LINGER, SNDBUF, RCVBUF, or DELAY)
Returns:
numeric value for specified option or -1 if the value is not available.
Throws:
IOException - if the connection was closed
See Also:
SocketConnection.setSocketOption(byte, int)

setSocketOption

public void setSocketOption(byte option,
                            int value)
                     throws IOException
Description copied from interface: SocketConnection
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.

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.

Specified by:
setSocketOption in interface SocketConnection
Parameters:
option - socket option identifier (KEEPALIVE, LINGER, SNDBUF, RCVBUF, or DELAY)
value - numeric value for specified option
Throws:
IOException - if the connection was closed
See Also:
SocketConnection.getSocketOption(byte)

SunSPOT API V6.0


Copyright © 2006-2010 Oracle. All Rights Reserved.