Class simu.net.Communicator
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class simu.net.Communicator

java.lang.Object
   |
   +----java.lang.Thread
           |
           +----simu.net.Communicator

public class Communicator
extends Thread
Version:
1.0 20-Mar-97
Author:
Andre Campeau

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:

  1. Spawned to interact with a dispatcher and obtain the anonymous port number to use when subsequently connecting to the SCPCommunicator.
  2. Spawned by an object (such as a SNE) to be permanently listening (as a daemon) for communication.
  3. Spawned by an object (such as a SNE) to communicate with the SCP, after which the Communicator thread terminates.

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:

See Also:
SCPCommunicator

Constructor Index

 o Communicator(Hashtable, int)
This Communicator constructor spawns a listener daemon thread.
 o Communicator(String, int[])
This Communicator constructor interacts with a dispatcher.
 o Communicator(String[], String, String, int)
This Communicator constructor spawns a temporary sender thread.

Method Index

 o Receive(DataInputStream, PrintStream)
The Receive method reads data from the connected socket, and sends a reply as appropriate.
 o run()
The run method contains the code that will be run by the Communicator thread.
 o Send(String[], String, DataInputStream, PrintStream)
The Send method sends data out of the connected socket, and waits for a reply as appropriate.

Constructors

 o Communicator
  public Communicator(String SendIP,
                      int SendPort[])
This Communicator constructor interacts with a dispatcher.

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.

Parameters:
SendIP - The IP address of the remote object.
SendPort - The listener port of the remote object.
 o Communicator
  public Communicator(Hashtable LocalTable,
                      int ListenerPort)
This Communicator constructor spawns a listener daemon thread.

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.

Parameters:
LocalTable - A pointer to the local Hashtable. Note that if a SNE is constructing the Communicator, the localTable may be the MIB. In general, however, there is no guarantee that this will be the case.
ListenerPort - The port the daemon listens on.
 o Communicator
  public Communicator(String ReceiveData[],
                      String SendData,
                      String SendIP,
                      int SendPort)
This Communicator constructor spawns a temporary sender thread.

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.

Parameters:
ReceiveData[] - The String (of size 1) where received data is stored.
SendData - The data to be sent to the remote object.
SendIP - The IP address of the remote object.
SendPort - The listener port of the remote object.

Methods

 o Receive
  public void Receive(DataInputStream dis,
                      PrintStream ps)
The Receive method reads data from the connected socket, and sends a reply as appropriate.

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.

Parameters:
dis - The data input stream attached to the socket connection.
ps - The output printstream attached to the socket connection.
 o Send
  public void Send(String receiveData[],
                   String sendData,
                   DataInputStream dis,
                   PrintStream ps)
The Send method sends data out of the connected socket, and waits for a reply as appropriate.

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.

Parameters:
dis - The data input stream attached to the socket connection.
ps - The output printstream attached to the socket connection.
 o run
  public void run()
The run method contains the code that will be run by the Communicator thread.
Overrides:
run in class Thread

All Packages  Class Hierarchy  This Package  Previous  Next  Index