/* * Salamander Transport Layer * * Michael J. Willis (violator@umich.edu) * * $Workfile: SalClientTest.java $ * $Author: rmalan $ * $Date: 1997/07/16 02:22:15 $ * $Revision: 1.2 $ */ /* * This file shows a very simple example of how to use the Salamander Transport * Layer in a java application. * The file contains two class definitions. The SalDataQueueTest class handles * the receipt of actual data from the server, while the SalClientTest class * performs all control-oriented communication with the server. */ import Salamander.*; // the Salamander package contains all necessary classes //package Salamander; import java.util.*; import java.io.*; /** * SalDataQueueTest implements the SalDataQueue interface, which allows this * class to receive data from the server automatically, via the callback * method enqueue(). * In general, an application should not do processing from within the enqueue * method, since the same thread is used to service packets from all services. * Instead, the class should put the packet into some type of container (i.e., * a queue) until a worker thread for the class needs the data. */ class SalDataQueueTest implements SalDataQueue { /** * enqueue() is called by the SalConnection object internally whenever * a new SalPacket addressed to this data queue has arrived. * @param p The SalPacket object that has arrived */ public void enqueue(SalPacket p) { // Grab the properties out of this packet (for demonstration) SalProperties props = p.getProperties(); Enumeration e = props.keys(); // print out all the headers (properties) for this packet while (e.hasMoreElements()) { String key = (String) e.nextElement(); System.out.println(key+": "+(String)props.get(key)); } // If there was any meaningful data, we could use it like this // InputStream in = p.getInputStream(); // read out the raw data... // in.readInt(); //....use data here.... } /** * Not currently implemented. */ public int getCurrentQueueLength() { return 0; } }