SunSPOT host API V6.0


com.sun.spot.io.j2me.socket
Class SocketConnection

java.lang.Object
  extended by com.sun.spot.io.j2me.socket.SocketConnection

public class SocketConnection
extends Object

This class provides the necessary implementation for a socket connection.

A SocketProxy must be running on the desktop in order to properly establish a connection.

The SocketConnection uses the following Manifest properties to establish the connection:
"com.sun.spot.io.j2me.socket.SocketConnection-BaseStationAddress" : IEEE address of the base station where the SocketProxy is running (can also be set as an argument to the VM)
"com.sun.spot.io.j2me.socket.SocketConnection-BaseStationPort" : Radiogram port to connect to, where the SocketProxy is running. (can also be set as an argument to the VM)

Author:
Martin Morissette

Nested Class Summary
 class SocketConnection.SocketInputStream
          Socket specific input stream.
 
Field Summary
protected  String basestationAddress
           
protected  OutputStream confirmStream
           
protected  StreamConnection conn
           
protected  boolean connected
           
protected static SocketConnection[] connections
           
static String DEFAULT_BASE_STATION_PORT
           
static Object DO_REQUEST_LOCK
           
protected  int opens
           
static int PACKET_TYPE_INET_GET_BY_NAME_REQUEST
           
static int PACKET_TYPE_INET_GET_BY_NAME_RESPONSE
           
static int PACKET_TYPE_INET_GETLOCALHOST_REQUEST
           
static int PACKET_TYPE_INET_GETLOCALHOST_RESPONSE
           
static int PACKET_TYPE_KILL_REQUEST
           
static int PACKET_TYPE_KILL_RESPONSE
           
static int PACKET_TYPE_MULTICAST_PORT_REQUEST
           
static int PACKET_TYPE_MULTICAST_PORT_RESPONSE
           
static int PACKET_TYPE_PORT_REQUEST
           
static int PACKET_TYPE_PORT_RESPONSE
           
protected  int port
           
static String SOCKET_PROXY_BASE_STATION_ADDRESS_MANIFEST_PROPERTY
           
static String SOCKET_PROXY_BASE_STATION_PORT_MANIFEST_PROPERTY
           
static String SOCKET_PROXY_PROXY_DISCOVER_RADIUS_MANIFEST_PROPERTY
           
static int SPOT_GLOBALS_FIRST_DO_SOCKET_KEY
           
 
Constructor Summary
SocketConnection(ProxyInitializer initializer, boolean timeouts)
          Create a SocketConnection object.
SocketConnection(String baseStationAddress, int radioPort, boolean timeouts, OutputStream confirmStream)
           
 
Method Summary
 void close()
          Disconnect and close the SocketConnection.
protected  void disconnect()
          Disconnect and close the SocketConnection.
static String doSocketProxyRequest(int requestType, String string, boolean timeouts, SocketConnection socketConnection, DatagramConnectionImpl datagramConnectionImpl)
           
static String doSocketProxyRequestPrim(int requestType, String string, boolean timeouts, SocketConnection socketConnection, DatagramConnectionImpl datagramConnectionImpl)
           
static String getAddressByHost(String host)
          Perform a DNS lookup on the host over a radidostream connection.
 SocketConnection.SocketInputStream getInputStream()
          Get a SocketInputStream object associated to this conneciton.
static String getLocalHost()
           
 com.sun.spot.io.j2me.socket.SocketConnection.SocketOutputStream getOutputStream()
          Get a SocketOutputStream object associated to this conneciton.
protected  void init(String baseStationAddress, int radioPort, boolean timeouts)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPOT_GLOBALS_FIRST_DO_SOCKET_KEY

public static final int SPOT_GLOBALS_FIRST_DO_SOCKET_KEY
See Also:
Constant Field Values

SOCKET_PROXY_BASE_STATION_ADDRESS_MANIFEST_PROPERTY

public static final String SOCKET_PROXY_BASE_STATION_ADDRESS_MANIFEST_PROPERTY
See Also:
Constant Field Values

SOCKET_PROXY_BASE_STATION_PORT_MANIFEST_PROPERTY

public static final String SOCKET_PROXY_BASE_STATION_PORT_MANIFEST_PROPERTY
See Also:
Constant Field Values

SOCKET_PROXY_PROXY_DISCOVER_RADIUS_MANIFEST_PROPERTY

public static final String SOCKET_PROXY_PROXY_DISCOVER_RADIUS_MANIFEST_PROPERTY
See Also:
Constant Field Values

DEFAULT_BASE_STATION_PORT

public static final String DEFAULT_BASE_STATION_PORT
See Also:
Constant Field Values

PACKET_TYPE_KILL_REQUEST

public static final int PACKET_TYPE_KILL_REQUEST
See Also:
Constant Field Values

PACKET_TYPE_KILL_RESPONSE

public static final int PACKET_TYPE_KILL_RESPONSE
See Also:
Constant Field Values

PACKET_TYPE_PORT_REQUEST

public static final int PACKET_TYPE_PORT_REQUEST
See Also:
Constant Field Values

PACKET_TYPE_PORT_RESPONSE

public static final int PACKET_TYPE_PORT_RESPONSE
See Also:
Constant Field Values

PACKET_TYPE_MULTICAST_PORT_REQUEST

public static final int PACKET_TYPE_MULTICAST_PORT_REQUEST
See Also:
Constant Field Values

PACKET_TYPE_MULTICAST_PORT_RESPONSE

public static final int PACKET_TYPE_MULTICAST_PORT_RESPONSE
See Also:
Constant Field Values

PACKET_TYPE_INET_GET_BY_NAME_REQUEST

public static final int PACKET_TYPE_INET_GET_BY_NAME_REQUEST
See Also:
Constant Field Values

PACKET_TYPE_INET_GET_BY_NAME_RESPONSE

public static final int PACKET_TYPE_INET_GET_BY_NAME_RESPONSE
See Also:
Constant Field Values

PACKET_TYPE_INET_GETLOCALHOST_REQUEST

public static final int PACKET_TYPE_INET_GETLOCALHOST_REQUEST
See Also:
Constant Field Values

PACKET_TYPE_INET_GETLOCALHOST_RESPONSE

public static final int PACKET_TYPE_INET_GETLOCALHOST_RESPONSE
See Also:
Constant Field Values

DO_REQUEST_LOCK

public static final Object DO_REQUEST_LOCK

connections

protected static SocketConnection[] connections

conn

protected StreamConnection conn

basestationAddress

protected String basestationAddress

port

protected int port

confirmStream

protected OutputStream confirmStream

opens

protected int opens

connected

protected boolean connected
Constructor Detail

SocketConnection

public SocketConnection(ProxyInitializer initializer,
                        boolean timeouts)
                 throws IllegalArgumentException,
                        IOException
Create a SocketConnection object.

Parameters:
initializer - Initializer string to send the proxy to init the connection.
timeouts - set to true to use timeouts
Throws:
IOException - when unable to establish the connection with the proxy
IllegalArgumentException - when the property "com.sun.spot.io.j2me.socket.SocketConnection-BaseStationAddress" is not set in the Manifest file or passed as an argument to the VM.

SocketConnection

public SocketConnection(String baseStationAddress,
                        int radioPort,
                        boolean timeouts,
                        OutputStream confirmStream)
                 throws IllegalArgumentException,
                        IOException
Throws:
IllegalArgumentException
IOException
Method Detail

doSocketProxyRequest

public static String doSocketProxyRequest(int requestType,
                                          String string,
                                          boolean timeouts,
                                          SocketConnection socketConnection,
                                          DatagramConnectionImpl datagramConnectionImpl)
                                   throws IOException
Throws:
IOException

doSocketProxyRequestPrim

public static String doSocketProxyRequestPrim(int requestType,
                                              String string,
                                              boolean timeouts,
                                              SocketConnection socketConnection,
                                              DatagramConnectionImpl datagramConnectionImpl)
                                       throws IOException
Throws:
IOException

getAddressByHost

public static String getAddressByHost(String host)
                               throws IOException
Perform a DNS lookup on the host over a radidostream connection.

Throws:
IOException

getLocalHost

public static String getLocalHost()
                           throws IOException
Throws:
IOException

init

protected void init(String baseStationAddress,
                    int radioPort,
                    boolean timeouts)
             throws IOException
Throws:
IOException

getInputStream

public SocketConnection.SocketInputStream getInputStream()
                                                  throws IOException
Get a SocketInputStream object associated to this conneciton.

Returns:
a SocketInputStream object associated to this conneciton.
Throws:
IOException

getOutputStream

public com.sun.spot.io.j2me.socket.SocketConnection.SocketOutputStream getOutputStream()
                                                                                throws IOException
Get a SocketOutputStream object associated to this conneciton.

Returns:
a SocketOutputStream object associated to this conneciton.
Throws:
IOException

disconnect

protected void disconnect()
                   throws IOException
Disconnect and close the SocketConnection.

Throws:
IOException

close

public void close()
           throws IOException
Disconnect and close the SocketConnection.

Throws:
IOException

SunSPOT host API V6.0


Copyright © 2006-2010 Oracle. All Rights Reserved.