|
datum API Documentation | ||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--datum.protocol.Server
A datum.protocol server that supports unlimited Connection's, as well as basic multicasting. To use the Server class, call its constructor, passing it a class that implemented the Receiver interface. The Server will immediately be listening for connections from datum.protocol clients. The Receiver interface class will be sent events coming from all of the connected clients. The sendAll methods can be used for basic multicasting purposes. Limits such as maximum number of clients, and read-only clients need to be implemented by the application using the Server class. You can get references to all the individual clients connected to the Server by saving the connection parameter on the connected() method of Receiver.
Example:
import datum.protocol.*;
import java.io.*;
import java.util.*;
public class ServerTest implements Receiver {
Server s;
public ServerTest() {
String[][] definitions = {{"TypeA", "FieldA1", "FieldA2"},
{"TypeB", "FieldB1", "FieldB2"}};
try {s = new Server(definitions, this);}
catch(IOException e) {System.out.println(e);}
}
public void error(Connection connection, String errorProtocol) {}
public void connected(Connection connection) {
Object[] message = {"TypeA", "Hello there!", new Integer(s.getNumClients())};
connection.send(message);
}
public void receivedData(Connection connection, Hashtable data) {}
public void disconnected(Connection connection) {}
}
Connection,
Receiver,
sendAll(java.lang.Object[])| Constructor Summary | |
Server(OutputStream outputStream)
Creates a new datum.protocol server that writes messages sent to the sendAll method to the given OutputStream. |
|
Server(Receiver receiver)
Creates a new datum.protocol server that listens on the default port. |
|
| Method Summary | |
void |
connected(Connection connection)
Do not use. |
void |
disconnectAll()
Disconnects all clients from the Server. |
void |
disconnected(Connection connection)
Do not use. |
void |
error(Connection connection,
String errorProtocol)
Do not use. |
int |
getNumClients()
Returns the number of clients currently connected to the Server. |
void |
receivedData(Connection connection,
Hashtable data)
Do not use. |
void |
run()
Do not use. |
void |
sendAll(Object[] message)
Sends a message built from an array of fields to all the clients connected to the server. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Server(Receiver receiver)
throws IOException
definitions - An array of message field name arrays. Each array
representing a message definition should be an array of field names,
the first field should be the message type.receiver - The class that will receive events from clients which connect
to the server.IOException - If a server socket can not be opened.public Server(OutputStream outputStream)
definitions - An array of message field name arrays. Each array
representing a message definition should be an array of field names,
the first field should be the message type.outputStream - A output stream that will be written to by sendAll()sendAll(java.lang.Object[])| Method Detail |
public void run()
run in interface Runnablepublic int getNumClients()
public void sendAll(Object[] message)
message - An array of fields which are delimated and concatenated into
a single message. The first field should be the message name.public void disconnectAll()
public void error(Connection connection,
String errorProtocol)
error in interface Receiverdatum.protocol.Receiverconnection - The connection which this error is coming from.errorMessage - A description of the error that occured.Receiver.disconnected(Connection)public void connected(Connection connection)
connected in interface Receiverdatum.protocol.Receiverconnection - The connection which has just been established.Connection.send(java.lang.Object[])
public void receivedData(Connection connection,
Hashtable data)
receivedData in interface Receiverdatum.protocol.Receiverconnection - The connection which received a message.data - The Hashtable which contains field name-value pairs from the message.Connection.getLibrary()public void disconnected(Connection connection)
disconnected in interface Receiverdatum.protocol.Receiverconnection - The connection which has just been dropped.
|
Up to datum |
||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||