Sun Microsystems V2.0 manual You can open server radiogram connections in a similar way

Page 33

There are some points to note about using datagrams:

Only datagrams obtained from the connection may be passed in send or receive calls on the connection. You cannot obtain a datagram from one connection and use it with another.

A connection opened with a specific address can only be used to send to that address. Attempts to send to other addresses will result in an exception.

It is permitted to open a server connection and a client connection on the same machine using the same port numbers. All incoming datagrams for that port will be routed to the server connection.

Currently, closing a server connection also closes any client connections on the same port.

Using system allocated ports

Most applications use perhaps one or two ports with fixed numbers (remember that each SPOT can open many connections on the same port, as long as they are to different remote SPOTs). However, some applications need to open variable numbers of connections to the same remote SPOT, and for such applications, it is convenient to ask the library to allocate free port numbers as required. To do this, simply exclude the port number from the url. So, for example:

RadiogramConnection conn = (RadiogramConnection)Connector.open("radiogram://0014.4F01.0000.0006");

This call will open a connection to the given remote SPOT on the first free port. To discover which port has been allocated, do

byte port = conn.getLocalPort();

You can open server radiogram connections in a similar way:

RadiogramConnection serverConn = (RadiogramConnection)Connector.open("radiogram://");

The same port allocation process works with radiostream connections. However, for radiostream connections, the port number is allocated only after either an input or output stream is opened. So, for example

RadiostreamConnection conn = (RadiostreamConnection)Connector.open("radiostream://0014.4F01.0000.0006:10");

//byte port = conn.getLocalPort(); // this would throw an exception as the

//port has not been allocated yet.

RadioInputStream is = (RadioInputStream)conn.openInputStream();

byte

port = conn.getLocalPort();

//

now the port can be accessed from the connection...

port

= is.getLocalPort();

//

...or from the input stream.

Adjusting connection properties

The RadiostreamConnection and RadiogramConnection classes provide a method for setting a

timeout on reception. For example:

RadiostreamConnection conn = (RadiostreamConnection)Connector.open("radiostream://0014.4F01.0000.0006:100");

conn.setTimeout(1000); // wait 1000ms for receive

33

Image 33
Contents Page Page Contents Http protocol support Introduction Deploying and running a sample application Building and deploying Sun Spot applicationsBuild Successful Total time 3 seconds \MyApplication Ant -Dport=COM2 info Total time 4 seconds \MyApplication Total time 0 seconds \MyApplication Incorporating utility classes into your application Deploying a pre-existing jarManifest and resources Excluding files from the compilationOther user properties Using the Basestation Built-in propertiesOverview Set up Base Station configuration Remote operationIntroduction Connect a Sun Spot base station Managing keys and sharing Sun SPOTs Using short names for SPOTsTake suitable actions during over-the-air downloads BackgroundSharing Sun SPOTs Changing the owner of a Sun SpotDeploying and running a host application What is protected?Generating a new key-pair LimitationsYour own host application Configuring network featuresIncorporating pre-existing jars into your host application Mesh routingHardware configurations and USB power Trace routeLogging Page Overview of an application ThreadsThread priorities Sun Spot device libraries Sun Spot device libraryDevice Interface Persistent properties Overriding the Ieee address Accessing flash memoryUsart Radio communication library Program Radiogram protocol Server end Client endYou can open server radiogram connections in a similar way Broadcasting Radio properties Turning the receiver off and on Conserving power using deep sleep mode Monitoring radio activityShallow Sleep Deep Sleep Activating deep sleep modePreconditions for deep sleeping USB inhibits deep sleepDeep sleep behaviour of the standard drivers Device Condition to permit deep sleepWriting a device driver Http protocol support Configuring the http protocolSocket Proxy GUI mode Configuring projects in an IDEClasspath configuration Javadoc/source configurationDebugging Ant selectapplication Configuring Eclipse as a debug client Configuring NetBeans as a debug clientAdvanced topics Using library suitesWith adderlib as your current directory, execute the command Use the command Using the spot client SpotSerialPortException other exception in serial port comms Reference Persistent system propertiesProperty name Meaning Contents of the lib directory Contents of the arm directoryMemory usage Start address Space UseContents of the bin directory preverify.exe Contents of the tests directory Contents of the upgrade directory