Code sample – TcpProxy  More information

Chapter 2: Secure TCP Socket Connections

Code sample – TcpService

// Create new TCP service
TcpService TCP= new TcpService();

// enable debug
TCP.setDebugEnabled(true);

// Declare security for connection with secure clients. 
// Keystore info need to be changed to custom values.
SSLStoreObject oKeyStore = new SSLStoreObject("keystore.txt");
oKeyStore.setPassword("password", false);

// Declare trust for clients authorized to connect
// truststore info need to be changed to custom values.
SSLStoreObject oTrustStore = new SSLStoreObject("truststore.txt");
oTrustStore.setPassword("trustword",false);

// Set security key and trust for server
TCP.setServerSecurity(oKeyStore,oTrustStore);
TCP.setServerSecurityEnabled(true);

// Set the server TCP Port to listen for client connections. 
// Warning, for secured clients, always use setServerInfo()
// After setServerSecurity() and setServerSecurityEnabled() , otherwise, 
// The server will start listening for standard connections instead.
// In this sample, the server will listen for secured connections on port 10000
// At this time the server will bound its socket on the specified port. TCP.setServerInfo(10000, 0);

// Set the target TCP port to forward data to.
// In this sample the server forwards data to standard connections on port 9999
// Target can be secured using setTargetSecurity(oTrustStore)
TCP.setTargetSecurityEnabled(false);
TCP.setTargetInfo("polaris",9999);

// Start the server on blocking mode (default)
TCP.startServer();

// Stop the server.
TCP.stopServer();




Copyright © 2005. Sybase Inc. All rights reserved. More information

View this book as PDF