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

Class simu.net.SCPCommunicator

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

public class SCPCommunicator
extends Thread
Version:
1.0 16-Mar-97
Author:
Andre Campeau

The SCPCommunicator class is used by the Simulator Control program (SCP) to communicate with remote objects on the simulated network environment. The simulated network environment is composed of Simulated Network Elements (SNEs) which simulate the behaviour of real network elements, such as printers and routers. The SNEs are Java programs executing on the local or remote computers.

The communication with the remote objects (usually SNEs) is accomplished using TCP socket connections. This way, the remote objects can be accessed regardless of whether they are on the local computer (localhost) or a remote computer on the network. This allows the simulated network environment to be extended to many computers, with SNEs running on each.

The SCPCommunicator class may be use in one of three ways:

  1. Spawned by the SCP to be permanently listening (as a daemon) for communication.
  2. Spawned by the Dispatcher to listen for one and only one incoming message, after which the SCPCommunicator thread terminates.
  3. Spawned by the SCP to communicate with a remote object, such as a SNE, after which the SCPCommunicator thread terminates.

Once the SCPCommunicator 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 SCPCommunicator 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 Communicator class.

Valid protocol messages that the SCPCommunicator can receive:

Valid protocol messages that the SCPCommunicator can send:

See Also:
Dispatcher, Communicator

Constructor Index

 o SCPCommunicator(Hashtable, String, String, int)
This SCPCommunicator constructor spawns a temporary sender thread.
 o SCPCommunicator(sned, int)
This SCPCommunicator constructor spawns a listener daemon thread.
 o SCPCommunicator(sned, ServerSocket)
This SCPCommunicator constructor spawns a temporary listener thread.

Method Index

 o isError()
The isError method returns the error state of the SCPCommunicator.
 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 SCPCommunicator thread.
 o Send(Hashtable, String, DataInputStream, PrintStream)
The Send method sends data out of the connected socket, and waits for a reply as appropriate.

Constructors

 o SCPCommunicator
  public SCPCommunicator(sned TheSned,
                         int ListenerPort)
This SCPCommunicator constructor spawns a listener daemon thread.

Preconditions: None.

Postconditions: The SCPCommunicator 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:
TheSned - A pointer to the SNE database, which is created by the SCP.
ListenerPort - The port the daemon listens on.
 o SCPCommunicator
  public SCPCommunicator(sned TheSned,
                         ServerSocket Listener)
This SCPCommunicator constructor spawns a temporary listener thread.

Preconditions: None.

Postconditions: The SCPCommunicator object is constructed, and a listener thread is spawned. The thread listens until the short-term objective is accomplished (i.e. receive remote data), then it terminates.

Parameters:
TheSned - A pointer to the SNE database, which is created by the SCP.
Listener - A pointer to the ServerSocket to listen on.
 o SCPCommunicator
  public SCPCommunicator(Hashtable RemoteData,
                         String SendData,
                         String SendIP,
                         int SendPort)
This SCPCommunicator constructor spawns a temporary sender thread.

Preconditions: None.

Postconditions: The SCPCommunicator object is constructed, and a 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 Hashtable.

Parameters:
RemoteData - The Hashtable where received remote 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 isError
  public boolean isError()
The isError method returns the error state of the SCPCommunicator.

Preconditions: None.

Postconditions: If an error has been previsouly detected, true is returned, otherwise false is returned. An error is detected if data cannot be sent to or received from the remote object that the SCPCommunicator is connected to.

 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 SNED 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(Hashtable remoteData,
                   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 SNED 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 SCPCommunicator thread.
Overrides:
run in class Thread

All Packages  Class Hierarchy  This Package  Previous  Next  Index