Class TcpLayer

  • All Implemented Interfaces:
    java.lang.AutoCloseable, TransportLayer, StreamAccessor

    public class TcpLayer
    extends java.lang.Object
    implements TransportLayer
    Class to handle all outgoing and incoming TCP packets over one TCP connection.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Will close the TCP connection to the server if its still open and free any resources of this connection.
      java.io.DataInputStream getInputStream()
      Returns the input stream for this stream accessor.
      java.io.DataOutputStream getOutpuStream()
      Returns the output stream for this stream accessor.
      boolean isClosed()
      Status of the connection/transport layer.
      void open()
      Opens the physical layer.
      void setTimeout​(int timeout)
      Enable/disable TIMEOUT with the specified timeout, in milliseconds.
      • Methods inherited from class java.lang.Object

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

    • Method Detail

      • setTimeout

        public void setTimeout​(int timeout)
                        throws java.io.IOException
        Description copied from interface: StreamAccessor
        Enable/disable TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStreamm associated with this StreamAcessor will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.
        Specified by:
        setTimeout in interface StreamAccessor
        Parameters:
        timeout - the specified timeout, in milliseconds.
        Throws:
        java.io.IOException - if there is an error in the underlying protocol, such as a TCP error.
      • getInputStream

        public java.io.DataInputStream getInputStream()
        Description copied from interface: StreamAccessor
        Returns the input stream for this stream accessor.
        Specified by:
        getInputStream in interface StreamAccessor
        Returns:
        the input stream.
      • isClosed

        public boolean isClosed()
        Description copied from interface: TransportLayer
        Status of the connection/transport layer.
        Specified by:
        isClosed in interface TransportLayer
        Returns:
        true if the connection is closes false otherwhise.
      • getOutpuStream

        public java.io.DataOutputStream getOutpuStream()
        Description copied from interface: StreamAccessor
        Returns the output stream for this stream accessor.
        Specified by:
        getOutpuStream in interface StreamAccessor
        Returns:
        the output stream.
      • open

        public void open()
                  throws java.io.IOException
        Description copied from interface: TransportLayer
        Opens the physical layer.
        Specified by:
        open in interface TransportLayer
        Throws:
        java.io.IOException - if an error occurred opening the stream.
      • close

        public void close()
                   throws java.io.IOException
        Will close the TCP connection to the server if its still open and free any resources of this connection.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface StreamAccessor
        Throws:
        java.io.IOException