Sun SPOT API
Green Release  


com.sun.spot.io.j2me.radiogram
Interface RadiogramConnection

All Superinterfaces:
Connection, DatagramConnection, ITimeoutableConnection
All Known Implementing Classes:
Protocol

public interface RadiogramConnection
extends ITimeoutableConnection, DatagramConnection

This interface defines the "radiogram" protocol - the radiogram protocol is a datagram-based protocol that allows the exchange of packets between two devices.

NOTE The current implementation is single-hop only: it can only be used to communicate between devices that are in direct radio range.

IMPORTANT This protocol is provided for test purposes and to allow creation of simple demonstrations. It is NOT designed to be used as the base for higher level or more complex protocols. If you want to create something more sophisticated write a new protocol that calls the LowPanPacketDispatcher directly. See IProtocolManager for more information.

To open a point-to-point connection do:

...
StreamConnection conn = (StreamConnection) Connector.open("radiogram://:");
...

where destinationAddr is the 64bit IEEE Address of the radio at the far end, and portNo is a port number in the range 0 to 127 that identifies this particular connection. Note that 0 is not a valid IEEE address in this implementation.

To establish a point-to-point connection both ends must open connections specifying the same portNo and corresponding IEEE addresses.

Once the connection has been opened, each end can obtain streams to use to send and receive data, eg:

...
DatagramConnection conn = (DatagramConnection) Connector.open("radiogram://" + targetIEEEAddress + ":10");
Datagram dg = conn.newDatagram(conn.getMaximumLength());
dg.writeUTF("My message");
conn.send(dg);
...
conn.receive(dg);
String answer = dg.readUTF();
...


The radiogram protocol also supports broadcast mode, where radiograms are delivered to all listeners on the given port. Because broadcast mode does not use I802.15.4 ACKing, there are no delivery guarantees.


...
DatagramConnection sendConn = (DatagramConnection) Connector.open("radiogram://broadcast:10");
dg.writeUTF("My message");
sendConn.send(dg);
...
DatagramConnection recvConn = (DatagramConnection) Connector.open("radiogram://:10");
recvConn.receive(dg);
String answer = dg.readUTF();



Method Summary
 
Methods inherited from interface com.sun.spot.peripheral.ITimeoutableConnection
getTimeout, setTimeout
 
Methods inherited from interface javax.microedition.io.DatagramConnection
getMaximumLength, getNominalLength, newDatagram, newDatagram, newDatagram, newDatagram, receive, send
 
Methods inherited from interface javax.microedition.io.Connection
close
 


Sun SPOT API
Green Release  


Copyright © 2006 Sun Microsystems, Inc. All Rights Reserved.