All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----java.lang.Thread | +----simu.net.SCPCommunicator
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:
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:
public SCPCommunicator(sned TheSned, int ListenerPort)
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.
public SCPCommunicator(sned TheSned, ServerSocket Listener)
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.
public SCPCommunicator(Hashtable RemoteData, String SendData, String SendIP, int SendPort)
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.
public boolean isError()
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.
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 SNED is queried to get the data, which is sent over the connection.
public void Send(Hashtable remoteData, 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 SNED is queried to get the data, which is sent over the connection.
public void run()
All Packages Class Hierarchy This Package Previous Next Index