Package ch.k43.util
Klasse KSocketClient
java.lang.Object
ch.k43.util.KSocketClient
- Alle implementierten Schnittstellen:
AutoCloseable
Supported TCP socket connections to non-TLS, TLS and TLS with client authentication.
Notes:
- The remote host certificate must be present in the JVM trusted store to be authenticated.
- If client authentication is required by the host, the JKS file with the client certificate must be accessible.
-
Konstruktorübersicht
KonstruktorBeschreibungKSocketClient
(String argHostName, int argHostPort) Class constructor to open TLS-secured socket to remote host.KSocketClient
(String argHostName, int argHostPort, boolean argTLS) Class constructor to open TLS-secured or non-secured socket to remote host.KSocketClient
(String argHostName, int argHostPort, boolean argTLS, String argKeyStoreFileName, char[] argKeyStorePassword) Class constructor to open TLS-secured or non-secured socket to remote host with client certificate.KSocketClient
(String argHostName, int argHostPort, String argKeyFileName, char[] argKeyFilePassword) Class constructor to open TLS-secured socket with client authentication to remote host. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
close()
Close the socket connection.boolean
flush()
Flush the output data.Return name of authenticated client based on the used client certificate.Return common name (without CN=) of the DN (distinguished name) from the used client certificate.Return used TCP cipher suite (Example: "TLS_AES_256_GCM_SHA384").Return last errorReturn used TCP connection protocol (Example: "TLSv1.3").boolean
Return connection stateboolean
Check if data is availableint
read
(char[] argData) Read socket into character arrayreadLine()
Read line from sockettoString()
String representation of object.boolean
write
(byte[] argData) Write byte array to socketboolean
write
(char[] argData) Write character array to socketboolean
Write string to socket
-
Konstruktordetails
-
KSocketClient
Class constructor to open TLS-secured socket to remote host.- Parameter:
argHostName
- Remote host nameargHostPort
- Remote host port
-
KSocketClient
Class constructor to open TLS-secured or non-secured socket to remote host.- Parameter:
argHostName
- Remote host nameargHostPort
- Remote host portargTLS
- True for TLS-secured socket, false for non-secured socket
-
KSocketClient
public KSocketClient(String argHostName, int argHostPort, boolean argTLS, String argKeyStoreFileName, char[] argKeyStorePassword) Class constructor to open TLS-secured or non-secured socket to remote host with client certificate.Note:
- Use KClientSocket.isConnected() to see if the connection was established
- For TLS client authentication, use the key store file name and password (JKS file)- Parameter:
argHostName
- Remote host nameargHostPort
- Remote host portargTLS
- True for TLS-secured socket, false for non-secured socketargKeyStoreFileName
- Key store file name to be loaded or nullargKeyStorePassword
- Key store file password or null
-
KSocketClient
public KSocketClient(String argHostName, int argHostPort, String argKeyFileName, char[] argKeyFilePassword) Class constructor to open TLS-secured socket with client authentication to remote host.- Parameter:
argHostName
- Remote host nameargHostPort
- Remote host portargKeyFileName
- Key store file name to be loaded or nullargKeyFilePassword
- Key store file password or null
-
-
Methodendetails
-
close
public void close()Close the socket connection.- Angegeben von:
close
in SchnittstelleAutoCloseable
-
flush
public boolean flush()Flush the output data.- Gibt zurück:
- boolean True if successful, false otherwise
-
getAuthenticatedClient
Return name of authenticated client based on the used client certificate.- Gibt zurück:
- DN name of peer principal or null if not TLS authenticated
- Seit:
- 2024.05.17
-
getAuthenticatedClientCN
Return common name (without CN=) of the DN (distinguished name) from the used client certificate.- Gibt zurück:
- Common name of peer principal or null if not TLS authenticated
- Seit:
- 2024.05.17
-
getCiphers
Return used TCP cipher suite (Example: "TLS_AES_256_GCM_SHA384").- Gibt zurück:
- TLS cipher suite or null
-
getLastError
Return last error- Gibt zurück:
- String Error message or null
-
getProtocol
Return used TCP connection protocol (Example: "TLSv1.3").- Gibt zurück:
- TLS protocol used or null
-
isConnected
public boolean isConnected()Return connection state- Gibt zurück:
- boolean True if connected, false otherwise
-
isDataAvailable
public boolean isDataAvailable()Check if data is available- Gibt zurück:
- boolean True if data is available, false otherwise
-
read
public int read(char[] argData) Read socket into character array- Parameter:
argData
- Character buffer- Gibt zurück:
- int Number of bytes read or -1
-
readLine
Read line from socket- Gibt zurück:
- String String read or null for end-of-data
-
toString
String representation of object. -
write
public boolean write(byte[] argData) Write byte array to socket- Parameter:
argData
- Byte array to be written- Gibt zurück:
- boolean True if successful, false otherwise
-
write
public boolean write(char[] argData) Write character array to socket- Parameter:
argData
- Character array to be written- Gibt zurück:
- boolean True if successful, false otherwise
-
write
Write string to socket- Parameter:
argLine
- String to be written- Gibt zurück:
- boolean True if successful, false otherwise
-