Class Socket

  • All Implemented Interfaces:
    adams.core.AdditionalInformationHandler, adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.QuickInfoSupporter, adams.core.ShallowCopySupporter<AbstractRatInput>, adams.core.SizeOfHandler, adams.core.Stoppable, adams.core.StoppableWithFeedback, BufferedRatInput, RatInput, Serializable

    public class Socket
    extends AbstractBufferedRatInput
    Listens on the specified port for incoming data.
    Can either output raw byte arrays or strings (using the specified encoding).

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -max-buffer <int> (property: maxBuffer)
        The maximum number of items to buffer.
        default: 65535
        minimum: 1
     
    -port <int> (property: port)
        The port to listen on.
        default: 8000
        minimum: 1
        maximum: 65535
     
    -timeout <int> (property: timeout)
        The timeout in milli-second for waiting on new client connections.
        default: 3000
        minimum: 100
     
    -output-string <boolean> (property: outputString)
        If enabled, a string with the specified encoding is generated from the incoming
        byte array.
        default: false
     
    -encoding <adams.core.base.BaseCharset> (property: encoding)
        The type of encoding for sending the data.
        default: Default
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_Port

        protected int m_Port
        the port to listen on.
      • m_Timeout

        protected int m_Timeout
        the timeout for the socket.
      • m_Encoding

        protected adams.core.base.BaseCharset m_Encoding
        the encoding to use.
      • m_OutputString

        protected boolean m_OutputString
        whether to output a string.
      • m_Server

        protected transient ServerSocket m_Server
        the socket in use.
      • m_Client

        protected transient Socket m_Client
        the current client socket.
    • Constructor Detail

      • Socket

        public Socket()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        Returns:
        a description suitable for displaying in the gui
      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class AbstractBufferedRatInput
      • setPort

        public void setPort​(int value)
        Sets the port to connect to.
        Parameters:
        value - the port
      • getPort

        public int getPort()
        Returns the port to connect to.
        Returns:
        the port
      • portTipText

        public String portTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setTimeout

        public void setTimeout​(int value)
        Sets the timeout in milli-second to wait for new connections.
        Parameters:
        value - the timeout in msec
      • getTimeout

        public int getTimeout()
        Returns the timeout in milli-second to wait for new connections.
        Returns:
        the timeout in msec
      • timeoutTipText

        public String timeoutTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the gui
      • setOutputString

        public void setOutputString​(boolean value)
        Sets whether to output a string.
        Parameters:
        value - true if to output a string
      • getOutputString

        public boolean getOutputString()
        Returns whether to output a string.
        Returns:
        true if to output a string
      • outputStringTipText

        public String outputStringTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setEncoding

        public void setEncoding​(adams.core.base.BaseCharset value)
        Sets the encoding to use.
        Parameters:
        value - the encoding, e.g. "UTF-8" or "UTF-16", empty string for default
      • getEncoding

        public adams.core.base.BaseCharset getEncoding()
        Returns the encoding to use.
        Returns:
        the encoding, e.g. "UTF-8" or "UTF-16", empty string for default
      • encodingTipText

        public String encodingTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getQuickInfo

        public String getQuickInfo()
        Returns a quick info about the actor, which will be displayed in the GUI.
        Specified by:
        getQuickInfo in interface adams.core.QuickInfoSupporter
        Overrides:
        getQuickInfo in class AbstractRatInput
        Returns:
        null if no info available, otherwise short string
      • doReceive

        protected String doReceive()
        Performs the actual reception of data.
        Specified by:
        doReceive in class AbstractRatInput
        Returns:
        null if successful, otherwise error message
      • cleanUp

        public void cleanUp()
        Cleans up data structures, frees up memory.
        Specified by:
        cleanUp in interface adams.core.CleanUpHandler
        Overrides:
        cleanUp in class AbstractBufferedRatInput