Page cover image

🖥️Socket Client

Low-level access to any server socket

KSocketClient Class Overview

  • TLS and Non-TLS Connection Support Enables secure and non-secure connections to server applications, providing flexibility for various use cases.

  • Client Authentication Supports client authentication using Java KeyStore (JKS) files for enhanced security during communication.

  • Versatile Read/Write Methods Provides efficient methods for reading and writing data in multiple formats, including byte[], char[], String, and line-based input.

Example

try (KSocketClient tlsSocket = new KSocketClient("example.com", 4443)) {
   KLog.abort(!tlsSocket.isConnected(), "Connect failed - " + tlsSocket.getLastError());

   while ((String hostLine = tlsSocket.readLine()) != null) {
      System.out.println(hostLine + K.getLineSeparator());
   }
}

Last updated