SunSPOT API V6.0


com.sun.spot.io.j2me.udp
Class UDPConnection

java.lang.Object
  extended by com.sun.squawk.io.ConnectionBase
      extended by com.sun.spot.peripheral.RadioConnectionBase
          extended by com.sun.spot.io.j2me.udp.UDPConnection
All Implemented Interfaces:
ITimeoutableConnection, Connection, DatagramConnection

public class UDPConnection
extends RadioConnectionBase
implements DatagramConnection

This class provides the "udp" protocol for accessing a node using datagrams. It is an implementor of DatagramConection


Field Summary
 
Fields inherited from class com.sun.spot.peripheral.RadioConnectionBase
DEFAULT_TIMEOUT
 
Constructor Summary
UDPConnection()
          DO NOT USE THIS CONSTRUCTOR - connections should be created using Connector.open(...)
UDPConnection(String addr, int portNo, boolean isServer, boolean timeouts)
          DO NOT USE THIS CONSTRUCTOR - connections should be created using Connector.open(...)
 
Method Summary
 void close()
          Close
 short getLocalPort()
           
 int getMaximumLength()
          Get the maximum length a datagram can be.
 int getNominalLength()
          Get the nominal length of a datagram.
 Inet6Address getRemoteAddress()
           
 short getRemotePort()
           
protected  boolean isBroadcast()
           
protected  boolean isServer()
           
 Datagram newDatagram(byte[] buf, int size)
          Create a new datagram object.
 Datagram newDatagram(byte[] buf, int size, String addr)
          Make a new datagram object.
 Datagram newDatagram(int size)
          Create a new datagram object.
 Datagram newDatagram(int size, String addr)
          Create a new datagram object.
 Connection open(String arg0, String arg1, int arg2, boolean arg3)
          Open a connection to a target.
 void receive(Datagram dgram)
          Receive a datagram.
protected  UDPPacket receivePacket()
           
protected  UDPPacket receivePacket(long timeout)
           
 void send(Datagram dgram)
          Send a datagram.
 
Methods inherited from class com.sun.spot.peripheral.RadioConnectionBase
getTimeout, setTimeout
 
Methods inherited from class com.sun.squawk.io.ConnectionBase
openDataInputStream, openDataOutputStream, openInputStream, openOutputStream
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPConnection

public UDPConnection(String addr,
                     int portNo,
                     boolean isServer,
                     boolean timeouts)
DO NOT USE THIS CONSTRUCTOR - connections should be created using Connector.open(...) Creates a new UDPConnection object.

Parameters:
addr - The IPv6 address of the remote end of the connection. If this is not specified then this end of the connection is a server connection.
portNo - The IPv6 TCP port number of the remote end of the connection. If this is a server connection, this port number is the port number of this end of the server connection.
isServer - Defines whether this is a server side connection.
timeouts - The default timeout for socket operations.

UDPConnection

public UDPConnection()
DO NOT USE THIS CONSTRUCTOR - connections should be created using Connector.open(...)

Method Detail

close

public void close()
           throws IOException
Description copied from class: ConnectionBase
Close

Specified by:
close in interface Connection
Overrides:
close in class ConnectionBase
Throws:
IOException - If an I/O error occurs

getMaximumLength

public int getMaximumLength()
Description copied from interface: DatagramConnection
Get the maximum length a datagram can be. Maximum length determines the maximum size of the datagram that can be created using the newDatagram method, and the maximum size of the datagram that can be sent or received.

Specified by:
getMaximumLength in interface DatagramConnection
Returns:
The maximum length of a datagram.

getNominalLength

public int getNominalLength()
Description copied from interface: DatagramConnection
Get the nominal length of a datagram. Nominal length refers to the size of the datagram that is stored into the data buffer. Nominal length may be equal or less than the maximum length of the datagram.

Specified by:
getNominalLength in interface DatagramConnection
Returns:
The nominal length of a datagram.

send

public void send(Datagram dgram)
          throws NoAckException,
                 ChannelBusyException,
                 NoRouteToHostException,
                 NoMeshLayerAckException,
                 SocketException
Description copied from interface: DatagramConnection
Send a datagram. The Datagram object includes the information indicating the data to be sent, its length, and the address of the receiver. The method sends length bytes starting at the current offset of the Datagram object, where length and offset are internal state variables of the Datagram object.

Specified by:
send in interface DatagramConnection
Parameters:
dgram - A datagram.
Throws:
NoAckException
ChannelBusyException
NoRouteToHostException
NoMeshLayerAckException
SocketException

receive

public void receive(Datagram dgram)
             throws IOException
Description copied from interface: DatagramConnection
Receive a datagram. When this method returns, the internal buffer in the Datagram object is filled with the data received, starting at the location determined by the offset state variable, and the data is ready to be read using the methods of the DataInput interface.

This method blocks until a datagram is received. The internal length state variable in the Datagram object contains the length of the received datagram. If the received data is longer than the length of the internal buffer minus offset, data is truncated.

This method does not change the internal read/write state variable of the Datagram object. Use method Datagram.reset to change the pointer before reading if necessary.

Specified by:
receive in interface DatagramConnection
Parameters:
dgram - A datagram.
Throws:
IOException - If an I/O error occurs.

newDatagram

public Datagram newDatagram(int size)
Description copied from interface: DatagramConnection
Create a new datagram object.

Specified by:
newDatagram in interface DatagramConnection
Parameters:
size - The size of the buffer needed for the datagram
Returns:
A new datagram

newDatagram

public Datagram newDatagram(int size,
                            String addr)
Description copied from interface: DatagramConnection
Create a new datagram object.

Specified by:
newDatagram in interface DatagramConnection
Parameters:
size - The size of the buffer needed for the datagram
addr - The I/O address to which the datagram will be sent
Returns:
A new datagram

newDatagram

public Datagram newDatagram(byte[] buf,
                            int size)
Description copied from interface: DatagramConnection
Create a new datagram object.

Specified by:
newDatagram in interface DatagramConnection
Parameters:
buf - The buffer to be used for the datagram
size - The size of the buffer needed for the datagram
Returns:
A new datagram

newDatagram

public Datagram newDatagram(byte[] buf,
                            int size,
                            String addr)
Description copied from interface: DatagramConnection
Make a new datagram object.

Specified by:
newDatagram in interface DatagramConnection
Parameters:
buf - The buffer to be used for the datagram
size - The size of the buffer needed for the datagram
addr - The I/O address to which the datagram will be sent
Returns:
A new datagram

isBroadcast

protected boolean isBroadcast()

isServer

protected boolean isServer()

open

public Connection open(String arg0,
                       String arg1,
                       int arg2,
                       boolean arg3)
                throws IOException
Description copied from class: ConnectionBase
Open a connection to a target.

Specified by:
open in class ConnectionBase
Parameters:
arg0 - The URL protocol
arg1 - The URL for the connection
arg2 - The access mode
arg3 - A flag to indicate that the caller wants timeout exceptions
Returns:
A new Connection object
Throws:
ConnectionNotFoundException - If the connection cannot be found.
IOException - If some other kind of I/O error occurs.

receivePacket

protected UDPPacket receivePacket(long timeout)

receivePacket

protected UDPPacket receivePacket()

getLocalPort

public short getLocalPort()

getRemotePort

public short getRemotePort()

getRemoteAddress

public Inet6Address getRemoteAddress()

SunSPOT API V6.0


Copyright © 2006-2010 Oracle. All Rights Reserved.