Klasse KSocketServer
- Alle implementierten Schnittstellen:
AutoCloseable
Notes:
- The constructor will load and start the KSocketServerListener thread which process all incoming client connects.
- The KSocketServerListener will start a separate KSocketServerThread for each accepted client connection.
- Siehe auch:
-
Konstruktorübersicht
KonstruktorBeschreibungKSocketServer
(int argLocalPort, Class<?> argClass) Start a non-TLS socket server.KSocketServer
(int argLocalPort, Class<?> argClass, String argKeyStoreFileName, char[] argKeyStorePassword) Start a TLS-secured socket server.KSocketServer
(int argLocalPort, Class<?> argClass, String argKeyStoreFileName, char[] argKeyStorePassword, String argTrustStoreFileName, char[] argTrustStorePassword) Start a TLS-secured socket server.KSocketServer
(int argLocalPort, String argClassName, boolean argTLS, String argKeyStoreFileName, char[] argKeyStorePassword, String argTrustStoreFileName, char[] argTrustStorePassword) Start a TLS-secured or non-secured socket server. -
Methodenübersicht
-
Konstruktordetails
-
KSocketServer
Start a non-TLS socket server.This constructor will start the KSocketServerListener thread to wait for all incoming client connections. For each successful client connect, the passed user class will be instantiated as a separate thread to handle the client connection.
Example:
KSocketServer server = new KSocketServer(9999, KSocketServerThreadSample.class); KLog.abort(!server.isActive(), "Server could not be started - " + server.getLastError()); ... server.close();
- Parameter:
argLocalPort
- Local host portargClass
- User class handling the client connections (subclass of KSocketServerThread)- Siehe auch:
-
KSocketServer
public KSocketServer(int argLocalPort, Class<?> argClass, String argKeyStoreFileName, char[] argKeyStorePassword) Start a TLS-secured socket server.This constructor will start the KSocketServerListener thread to wait for all incoming client connections. For each successful client connect, the passed user class will be instantiated as a separate thread to handle the client connection.
Example:
KSocketServer server = new KSocketServer(9999, KSocketServerThreadSample.class, "keyfile.jks", "Pa$$w0rd".toBytes()); KLog.abort(!server.isActive(), "Server could not be started - " + server.getLastError()); ... server.close();
- Parameter:
argLocalPort
- Local host portargClass
- User class handling the client socket request (must be subclass of KSocketServerThread)argKeyStoreFileName
- Key store file name to be loadedargKeyStorePassword
- Key store password- Siehe auch:
-
KSocketServer
public KSocketServer(int argLocalPort, Class<?> argClass, String argKeyStoreFileName, char[] argKeyStorePassword, String argTrustStoreFileName, char[] argTrustStorePassword) Start a TLS-secured socket server.This constructor will start the KSocketServerListener thread to wait for all incoming client connections. For each successful client connect, the passed user class will be instantiated as a separate thread to handle the client connection.
Example:
KSocketServer server = new KSocketServer(9999, KSocketServerThreadSample.class, "keystore.jks", "Pa$$w0rd".toBytes(), "truststore.jks", "Pa$$w0rd".toBytes()); if (!server.isActive()) { KLog.error("Server could not be started - " + server.getLastError()); ... } ... server.close();
- Parameter:
argLocalPort
- Local host portargClass
- User class handling the client socket request (must be subclass of KSocketServerThread)argKeyStoreFileName
- Key store file name to be loadedargKeyStorePassword
- Key store passwordargTrustStoreFileName
- Trust store file name to be loaded or null for non-TLSargTrustStorePassword
- Trust store password or null- Siehe auch:
-
KSocketServer
public KSocketServer(int argLocalPort, String argClassName, boolean argTLS, String argKeyStoreFileName, char[] argKeyStorePassword, String argTrustStoreFileName, char[] argTrustStorePassword) Start a TLS-secured or non-secured socket server.This constructor will start the KSocketServerListener thread to wait for all incoming client connections. For each successful client connect, the passed user class will be instantiated as a separate thread to handle the client connection.
Example:
KSocketServer server = new KSocketServer(9999, "ch.k43.util.KSocketServerThreadSample", true, "keystore.jks", "Pa$$w0rd".toBytes(), "truststore.jks", "Pa$$w0rd".toBytes()); if (!server.isActive()) { KLog.error("Server could not be started - " + server.getLastError()); ... } ... server.close();
- Parameter:
argLocalPort
- Local host portargClassName
- User class name handling the client socket requests (must be subclass of KSocketServerThread)argTLS
- True for TLS-secured socket, false for non-secured socketargKeyStoreFileName
- Key store file name to be loaded (TLS requirement) or null for non-TLSargKeyStorePassword
- Key store password or nullargTrustStoreFileName
- Trust store file name to be loaded or null for non-TLSargTrustStorePassword
- Trust store password or null- Siehe auch:
-
-
Methodendetails
-
close
public void close()Stop the socket server by terminating the KSocketServerListener thread. During shutdown, KSocketServerListener will itself terminate all client connections.- Angegeben von:
close
in SchnittstelleAutoCloseable
- Siehe auch:
-
getLastError
Return last error.- Gibt zurück:
- Error message or null
-
isActive
public boolean isActive()Return current status of the socket server.- Gibt zurück:
- True if server is active, false otherwise
-
toString
String representation of object.
-