Information Technology Reference
In-Depth Information
In the radio stream case, individual SPOT devices are all assigned URLs of the
format
radiostream://<DestAddress>:<PortNumber>
Where DestAddress is a 64-bit IEEE address of the remote SPOT, and
PortNumber is an integer number in the range [0,255] which serves as the
identifier of the port for this particular connection. Once a connection is
opened, through a call to the Connector.open() method, the programmer is able
to communicate with the remote SPOT in the standard Java fashion, using
DataStreams:
RadiostreamConnection conn =
(RadiostreamConnection)
Connector.open(“radio://00AB.CC21.00A0.0006:100”);
DataOutputStream dos = conn.openDataOutputStream();
try{
dos.writeUTF(“A message”);
dos.flush();
} catch (NoRouteException e) {
System.out.println (“00AB.CC21.00A0.0006 is unreachable”);
} finally {
dos.close();
conn.close();
In order for this example to work, the remote SunSPOT at 00AB.CC21.00A0.0006
must also open a connection to the calling SunSPOT, on the same port (100). It
should also open a DataInputStream, and issue a call to readUTF().
In the case of the radiogram protocol, the situation is a little bit different.
There is a difference in how the connection is opened on the client side and on
the server side (the server listens for requests on the specified port, while the client
issues a request using the server's URL and the same specified port. The URLs
are of the form
radiogram://<Address>:<Port>
The data itself has to be packed into datagrams, prior to sending:
RadiogramConnection conn =
(RadiogramConnection)Connector.open(“radiogram://
00AB.CC21.00A0.0006:10”);
Datagram dg = conn.newDatagram(conn.getMaximumLength());
try {
dg.writeUTF(“A message”);
conn.send(dg);
} catch (NoRouteException e) {
System.out.println (“00AB.CC21.00A0.0006 is unreachable “);
} finally {
conn.close();
}
Search WWH ::




Custom Search