Code sample – JSSL plug-in  Code sample – TcpService

Chapter 2: Secure TCP Socket Connections

Code sample – TcpProxy

int     serverPort              = 10000;
String  serverHost              = "localhost";
String  sampleData              = new String("AAFirst|Last|M|40|CABB");
String  sTrustStoreFileName     = "truststore.txt";
String  sTrustStorePassword     = "trustword";

// Create new TCP proxy instance 
m_tcp = new TcpProxy();

// enable debug
m_tcp.setDebugEnabled(true);

// connect to a secure socket
m_tcp.connectSecure(serverHost, serverPort, sTrustStoreFileName,
     sTrustStorePassword);
//if (!m_tcp.isConnected())
//    throw new Exception("Failed to connect to target TcpService")

// Prepare a sample data to send
byte[] bDat = sampleData.getBytes();
byte[] bRes = null; 

// Sending data
System.out.println("Sending " + bDat.length + " bytes");
m_tcp.send(bDat);

// Receiving data
bRes = m_tcp.receive();
if (bRes != null)
     System.out.println( new String(bRes));
else
bRes=null;
System.out.println("complete.");

// disconnect
m_tcp.disconnect();
m_tcp = null;




Copyright © 2005. Sybase Inc. All rights reserved. Code sample – TcpService

View this book as PDF