Class KSocketServerThread

java.lang.Object
java.lang.Thread
ch.k43.util.KSocketServerThread
All Implemented Interfaces:
AutoCloseable, Runnable
Direct Known Subclasses:
KHTTPServerThread, KSocketServerThreadSample

public abstract class KSocketServerThread extends Thread implements AutoCloseable
Class to handle user connections accepted by KSocketServerListener. The input is read as characters while output is sent as bytes.
See Also:
  • Method Details

    • close

      public void close()
      Close the socket connection.
      Specified by:
      close in interface AutoCloseable
    • getAuthenticatedClient

      public String getAuthenticatedClient()
      Return name of authenticated client based on the used client certificate.
      Returns:
      DN name of peer principal or null if not TLS authenticated
      Since:
      2024.05.17
    • getAuthenticatedClientCN

      public String getAuthenticatedClientCN()
      Return common name (without CN=) of the DN (distinguished name) from the used client certificate.
      Returns:
      Common name of peer principal or null if not TLS authenticated
      Since:
      2024.05.17
    • getCiphers

      public String getCiphers()
      Return used TCP cipher suite (Example: "TLS_AES_256_GCM_SHA384").
      Returns:
      TLS cipher suite or null
    • getLastError

      public String getLastError()
      Return last error.
      Returns:
      Error message or null
    • getProtocol

      public String getProtocol()
      Return used TCP connection protocol (Example: "TLSv1.3").
      Returns:
      TLS protocol used or null
    • isConnected

      public boolean isConnected()
      Return connection state.
      Returns:
      True if connected, false otherwise
    • isDataAvailable

      public boolean isDataAvailable()
      Check if data is available without blocking.
      Returns:
      True if data is available, false otherwise
    • isSecuredConnection

      public boolean isSecuredConnection()
      Check if connection is TLS secured.
      Returns:
      True if connection is TLS secured, false otherwise
    • read

      public int read(char[] argData)
      Read socket into character array.
      Parameters:
      argData - Character buffer
      Returns:
      Number of bytes read or -1
    • readLine

      public String readLine()
      Read line from socket.
      Returns:
      String read or null for end-of-data
    • run

      public void run()
      Main thread entry point - Will be overwritten by user class.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • toString

      public String toString()
      String representation of object.
      Overrides:
      toString in class Thread
      Since:
      2024.08.23
    • write

      public boolean write(char[] argData)
      Write byte array to socket.
      Parameters:
      argData - Character array to be written
      Returns:
      True if successful, false otherwise
    • write

      public boolean write(byte[] argData)
      Write character array to socket.
      Parameters:
      argData - Byte to be written
      Returns:
      True if successful, false otherwise
    • write

      public boolean write(String argLine)
      Write string to socket.
      Parameters:
      argLine - String to be written
      Returns:
      True if successful, false otherwise
    • writeLine

      public boolean writeLine(String argLine)
      Write line terminated with a platform dependent end-of-line to socket.
      Parameters:
      argLine - String to be written
      Returns:
      True if successful, false otherwise
      Since:
      2024.05.25