All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----java.lang.Thread | +----simu.net.Communicator
The Communicator class is used by objects running in the simulated network environment to communicate with the Simulator Control Program (SCP). In most cases, the objects would be Simulated Network Elements (SNEs) which simulate the behaviour of real network elements, such as printers and routers. The SNEs are Java programs executing on computers which are part of the simulated network.
The communication with the Simulator Control Program is accomplished using TCP socket connections. This way, the SCP can be accessed regardless of what computer it's running on. This allows the simulated network environment to be extended to many computers, with SNEs running on each.
The Communicator class may be use in one of three ways:
Once the Communicator is constructed, the guts of it (the parts that send and receive data) are spawned as a separate thread (a daemon thread in case 1 above). Receive and Send methods exist to handle the sending and receiving of data once the socket connections have been established.
The Communicator communicates with other objects on the network using an established protocol. Any incoming messages that do not adhere to the protocol are not processed. A similar protocol is used by the SCPCommunicator class.
Valid protocol messages that the Communicator can receive:
Valid protocol messages that the Communicator can send:
public Communicator(String SendIP, int SendPort[])
Preconditions: None.
Postconditions: The dispatcher will accept a socket connection, pass the next free port number through the socket, then close the socket connection. The purpose of this thread is to obtain the next free port number from a dispatcher and return it to the caller, after which it terminates.
public Communicator(Hashtable LocalTable, int ListenerPort)
Preconditions: None.
Postconditions: The Communicator object is constructed, and a listener thread is spawned. The thread acts as a daemon and listens continuously for incoming data (and possibly sends data as a reply). The thread is terminated when the all non-daemon threads in the JVM terminate.
public Communicator(String ReceiveData[], String SendData, String SendIP, int SendPort)
Preconditions: None.
Postconditions: The Communicator object is constructed, and a temporary sending thread is spawned. Data is sent to the specified IP address and port, after which data may be received over the same connection. Any received data is stored in a String array of size 1.
public void Receive(DataInputStream dis, PrintStream ps)
Preconditions: The listener thread has accepted a connection request from a remote object, and the input and output streams have been attached to the connection.
Postconditions: Data is received from the remote object over the socket connection. If the remote object expects a reply, the localTable is queried to get the data, which is sent over the connection.
public void Send(String receiveData[], String sendData, DataInputStream dis, PrintStream ps)
Preconditions: The thread has made a connection to the remote object, and the input and output streams have been attached to the connection.
Postconditions: Data is sent to the remote object over the socket connection. If the remote object expects a reply, the localTable is queried to get the data, which is sent over the connection.
public void run()
All Packages Class Hierarchy This Package Previous Next Index