Class Server


  • public class Server
    extends java.lang.Object
    Server that opens a BSD socket for communication with simulation engine.
    Since:
    Ptolemy II 8.0
    Version:
    $Id$
    Author:
    Michael Wetter
    • Field Summary

      Fields 
      Modifier and Type Field Description
      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 Summary

      Constructors 
      Constructor 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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • dblVal

        protected double[] dblVal
        The array that contains the last double values read from the socket .
      • flaFroCli

        protected int flaFroCli
        The communication flag read during the socket read command.
      • serSoc

        protected java.net.ServerSocket serSoc
        The server socket.
      • simTimRea

        protected double simTimRea
        The current simulation time as received from the client.
      • simTimWri

        protected double simTimWri
        The simulation time last written to the client.
      • verNo

        protected int verNo
        The version number of the socket implementation.
    • Constructor Detail

      • Server

        public Server​(int timOut)
               throws java.io.IOException
        Construct a server on any available port.
        Parameters:
        timOut - Socket time out in milliseconds.
        Throws:
        java.io.IOException - If the server socket cannot be opened.
      • Server

        public Server​(int portNo,
                      int timOut)
               throws java.io.IOException
        Construct a server on the port specified by portNo.
        Parameters:
        portNo - Port number for BSD socket.
        timOut - Socket time out in milliseconds.
        Throws:
        java.io.IOException - If the server socket cannot be opened.
    • Method Detail

      • getLocalPort

        public int getLocalPort()
        Get the port number.
        Returns:
        The port number.
      • write

        public void write​(int flagToClient,
                          double curTim,
                          double[] dblVal)
                   throws java.io.IOException
        Write data to the socket.
        Parameters:
        flagToClient - The communication flag.
        curTim - The current simulation time.
        dblVal - The array with double values.
        Throws:
        java.io.IOException - If a communication problems occur.
      • getClientFlag

        public int getClientFlag()
        Returns the last communication flag read from the socket.
        Returns:
        The communication flag.
      • getDoubleArray

        public double[] getDoubleArray()
        Return the last double array read from the socket.
        Returns:
        dblVal The array with double values.
      • getSimulationTimeWrittenToClient

        public double getSimulationTimeWrittenToClient()
        Return the last simulation time written to the client.
        Returns:
        The last simulation time written to the client.
      • getSimulationTimeReadFromClient

        public double getSimulationTimeReadFromClient()
        Return the last simulation time read from the client.
        Returns:
        The last simulation time read from the client.
      • read

        public void read()
                  throws java.io.IOException,
                         java.net.SocketTimeoutException
        Read data from the socket.
        Throws:
        java.io.IOException - If communication problems occur.
        java.net.SocketTimeoutException - If the socket does not respond.
      • close

        public void close()
                   throws java.io.IOException
        Close the socket.
        Throws:
        java.io.IOException - If an I/O error occurs when closing the socket.
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Main method that can be used for testing.
        Parameters:
        args - An array of length 1 that names the port to be used
        Throws:
        java.lang.Exception - If anything goes wrong.