public class Server
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) java.net.Socket |
cliSoc
The client socket.
|
protected double[] |
dblVal
The array that contains the last double values read from the socket .
|
protected int |
flaFroCli
The communication flag read during the socket read command.
|
protected java.net.ServerSocket |
serSoc
The server socket.
|
protected double |
simTimRea
The current simulation time as received from the client.
|
protected double |
simTimWri
The simulation time last written to the client.
|
protected int |
verNo
The version number of the socket implementation.
|
Constructor and Description |
---|
Server(int timOut)
Construct a server on any available port.
|
Server(int portNo,
int timOut)
Construct a server on the port specified by portNo.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the socket.
|
int |
getClientFlag()
Returns the last communication flag read from the socket.
|
double[] |
getDoubleArray()
Return the last double array read from the socket.
|
int |
getLocalPort()
Get the port number.
|
double |
getSimulationTimeReadFromClient()
Return the last simulation time read from the client.
|
double |
getSimulationTimeWrittenToClient()
Return the last simulation time written to the client.
|
static void |
main(java.lang.String[] args)
Main method that can be used for testing.
|
void |
read()
Read data from the socket.
|
void |
write(int flagToClient,
double curTim,
double[] dblVal)
Write data to the socket.
|
java.net.Socket cliSoc
protected double[] dblVal
protected int flaFroCli
protected java.net.ServerSocket serSoc
protected double simTimRea
protected double simTimWri
protected int verNo
public Server(int timOut) throws java.io.IOException
timOut
- Socket time out in milliseconds.java.io.IOException
- If the server socket cannot be opened.public Server(int portNo, int timOut) throws java.io.IOException
portNo
- Port number for BSD socket.timOut
- Socket time out in milliseconds.java.io.IOException
- If the server socket cannot be opened.public int getLocalPort()
public void write(int flagToClient, double curTim, double[] dblVal) throws java.io.IOException
flagToClient
- The communication flag.curTim
- The current simulation time.dblVal
- The array with double values.java.io.IOException
- If a communication problems occur.public int getClientFlag()
public double[] getDoubleArray()
public double getSimulationTimeWrittenToClient()
public double getSimulationTimeReadFromClient()
public void read() throws java.io.IOException, java.net.SocketTimeoutException
java.io.IOException
- If communication problems occur.java.net.SocketTimeoutException
- If the socket does not respond.public void close() throws java.io.IOException
java.io.IOException
- If an I/O error occurs when closing the socket.public static void main(java.lang.String[] args) throws java.lang.Exception
args
- An array of length 1 that names the port
to be usedjava.lang.Exception
- If anything goes wrong.