Exceptions
When an error occurs in a Spread method, a SpreadException is thrown. One example is if receive() is called on a SpreadConnection() object before connect() is called on that object. Another example is calling leave() on a SpreadGroup object before calling join() on that object. Any method that is declared as throwing a SpreadException must be placed within a try-catch block:
try
{
connection.multicast(message);
}
catch(SpreadException e)
{
e.printStackTrace();
System.exit(1);
}
If you do not want to handle specific exceptions, but just want to exit with an error whenever a SpreadException is thrown, you can place your main code within one try-catch block:
public final static void main(String args[])
{
try
{
...
}
catch(SpreadException e)
{
e.printStackTrace();
System.exit(1);
}
}
More specific exceptions will probably be added at some future point. These exceptions will be extended from SpreadException, so code written to handle SpreadExceptions will also be catch any future exceptions that are added.
Applets
When using Java in an applet, there is usually a security manager installed, which restricts what your code is allowed to do. For example, when running an applet in a web browser, the code is not allowed to make Internet connections to any place other than the machine running the web server. So, if Spread is running in an applet, in a web browser, the spread daemon must also be running on the machine running the web server. The following code can be used, in the class that extends Applet, to get an InetAddress object for the machine running the web server:
InetAddress host = InetAddress.getByName(getCodeBase().getHost());
Samples
Two sample java applications are included with the Spread interface for Java. User is an example of how to write a simple user in Java. It is similar to
the C library sample, user.c. Flooder is an example of a flooder that can help test performance. It is similar to the
C library sample, flooder.c.