Class SimpleTCP.Connection

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Runnable
    Enclosing class:
    SimpleTCP

    protected class SimpleTCP.Connection
    extends java.lang.Object
    implements java.lang.Runnable, java.io.Closeable
    1 connection per peer to send and receive messages
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] buffer  
      protected java.io.DataInputStream in  
      protected java.io.DataOutputStream out  
      protected IpAddress peer_addr  
      protected Runner runner  
      protected java.net.Socket sock  
      protected java.util.concurrent.atomic.AtomicInteger writers  
    • Constructor Summary

      Constructors 
      Constructor Description
      Connection​(java.net.Socket sock)  
    • Field Detail

      • sock

        protected final java.net.Socket sock
      • peer_addr

        protected final IpAddress peer_addr
      • in

        protected final java.io.DataInputStream in
      • out

        protected final java.io.DataOutputStream out
      • runner

        protected final Runner runner
      • buffer

        protected byte[] buffer
      • writers

        protected final java.util.concurrent.atomic.AtomicInteger writers
    • Constructor Detail

      • Connection

        public Connection​(java.net.Socket sock)
                   throws java.lang.Exception
        Throws:
        java.lang.Exception
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • send

        protected void send​(byte[] buffer,
                            int offset,
                            int length)
                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • createBufferedOutputStream

        protected java.io.BufferedOutputStream createBufferedOutputStream​(java.io.OutputStream out)
      • createBufferedInputStream

        protected java.io.BufferedInputStream createBufferedInputStream​(java.io.InputStream in)