ByteCommunications implemets two abstractions of a communication channel:
public class ByteSender { public ByteSender(String theName) { ... } public void deliver(Address theDest, byte[] data) { ... } ... }The deliver method sends a string of bytes to the destination address. The bytes to be sent are contained in the array data which is the second parameter of the method. The first element of the array data[0] must contain the number of data bytes to be delivered. Thus the maximum number of bytes that can be sent is 255.
public class ByteReceiver { public ByteReceiver(String theName, Address theAddr) { ... } public byte[] receive() { ... } ... }The receive method receives and returns a buffer of bytes. The implementation of receive assumes that it first receives a byte containing a counter of the number of bytes to be further received. After reading this first byte, it allocates the receiver buffer and receives the rest of the message. A maximum of 255 bytes can be eceived and returned.
An example of a Client-Server application implemented with Send-Receive is given in ClientWithSR and ServerWithSR. Both participants use class Configuration where some addresses are associated with names. Client and Server exchange messages of a custom format, defined by the Message class. These messages are transformed into the binary format needed for delivery (an array of bytes, having at index 0 the counter of number of bytes following in the array) by the Marshaller.
In order to run this example, launch first the Server and after this the Client.
public class Requestor { public Requestor(String theName) { ... } public byte[] deliver_and_wait_feedback(Address theDest, byte[] data) {... } ... }The deliver_and_wait_feedback method sends a string of bytes to the destination address, then waits to receive an answer on the same communication channel, and returns the bytes representing the answer. The bytes to be sent are contained in the array data which is the second parameter of the method. The first element of the array data[0] must contain the number of data bytes to be delivered. Thus the maximum number of bytes that can be sent is 255.
public class Replyer { public Replyer(String theName, Address theAddr) { ... } public void receive_transform_and_send_feedback(ByteStreamTransformer t) { ... } ... }The receive_transform_and_send_feedback method receives a buffer of bytes, transforms them using the ByteStreamTransformer, and sends back on the same communication channel the buffer containing the transformed bytes. Specific servers will have to provide different implementations of the ByteStreamTransformer interface.
public interface ByteStreamTransformer { public byte[] transform(byte[] in); }Un exemplu de client si server implementati cu Request-Reply e dat in ClientWithRR si ServerWithRR.