Class TcpProtocol

  • Direct Known Subclasses:
    CloudProtocol

    public class TcpProtocol
    extends Protocol
    Used for sending packets to the SmartInspect Console over a TCP socket connection.

    This class is used for sending packets over a TCP connection to the Console. It is used when the 'tcp' protocol is specified in the SmartInspect.setConnections(java.lang.String) connections string. Please see the isValidOption method for a list of available protocol options.

    Thread Safety: The public members of this class are threadsafe.

    • Field Detail

      • fHostName

        protected String fHostName
      • fTimeout

        protected int fTimeout
      • fPort

        protected int fPort
    • Constructor Detail

      • TcpProtocol

        public TcpProtocol()
        Creates and initializes a TcpProtocol instance. For a list of available TCP protocol options, please refer to the isValidOption method.
    • Method Detail

      • getName

        protected String getName()
        Overridden. Returns "tcp".
        Specified by:
        getName in class Protocol
        Returns:
        Just "tcp"
      • isValidOption

        protected boolean isValidOption​(String name)
        Validates if a protocol option is supported. Overridden method.

        The following table lists all valid options, their default values and descriptions for the TCP protocol:

        Tcp protocol options
        Valid Options Default Value Description
        host "127.0.0.1" Specifies the hostname where the Console is running
        port 4228 Specifies the Console port
        timeout 30000 Specifies the connect, receive and send timeout in milliseconds

        For further options which affect the behavior of this protocol, please have a look at the documentation of the Protocol.isValidOption method of the parent class. Example:

         SiAuto.si.setConnections("tcp()");
         SiAuto.si.setConnections("tcp(host=\\"localhost\\", port=4229)");
         SiAuto.si.setConnections("tcp(timeout=2500)");
         
        Overrides:
        isValidOption in class Protocol
        Parameters:
        name - The option name to validate
        Returns:
        True if the option is supported and false otherwise
      • buildOptions

        protected void buildOptions​(ConnectionsBuilder builder)
        Overridden. Fills a ConnectionsBuilder instance with the options currently used by this TCP protocol.
        Overrides:
        buildOptions in class Protocol
        Parameters:
        builder - The ConnectionsBuilder object to fill with the current options of this protocol
      • loadOptions

        protected void loadOptions()
        Overridden. Loads and inspects TCP specific options.

        This method loads all relevant options and ensures their correctness. See isValidOption for a list of options which are recognized by the TCP protocol

        Overrides:
        loadOptions in class Protocol
      • internalConnect

        protected void internalConnect()
                                throws Exception
        Overridden. Creates and connects a TCP socket. This method tries to connect a TCP socket to a SmartInspect Console. The hostname and port can be specified by passing the "hostname" and "port" options to the initialize method. Furthermore, it is possible to specify the connect timeout by using the "timeout" option.
        Specified by:
        internalConnect in class Protocol
        Throws:
        Exception - if creating or connecting the socket failed
      • internalWritePacket

        protected void internalWritePacket​(Packet packet)
                                    throws Exception
        Overridden. Sends a packet to the Console.

        This method sends the supplied packet to the SmartInspect Console and waits for a valid response.

        Specified by:
        internalWritePacket in class Protocol
        Parameters:
        packet - The packet to write
        Throws:
        Exception - If sending the packet to the Console failed
      • internalValidateWritePacketAnswer

        protected void internalValidateWritePacketAnswer​(int bytesRead,
                                                         byte[] answerBytes)
                                                  throws Exception
        Throws:
        Exception
      • internalDisconnect

        protected void internalDisconnect()
                                   throws Exception
        Overridden. Closes the TCP socket connection.

        This method closes the underlying socket handle if previously created and disposes any supplemental objects.

        Specified by:
        internalDisconnect in class Protocol
        Throws:
        Exception - If Closing the TCP socket failed