Listing 2: SSLClientSide.java (location: C:\j2sse\client\)
import java.net.*;
import java.io.*;
import javax.net.*;
import javax.net.ssl.*;
class contact_server{
Socket SSLsocket=null; //client socket
PrintWriter out=null; //in stream
BufferedReader in=null; //out stream
InputStreamReader ISR=null;
String in_str=null;
String out_str=null;
BufferedReader message=null;
public contact_server(){}
void send_message()
{
try{
SocketFactory SSLfabrica=SSLSocketFactory.getDefault();
SSLsocket=SSLfabrica.createSocket("127.0.0.1",443);
}catch(IOException e)
{
System.out.println("Error:"+e.getMessage());
System.exit(1);
}
try{
out=new PrintWriter(SSLsocket.getOutputStream(),true);
ISR=new InputStreamReader(SSLsocket.getInputStream());
in=new BufferedReader(ISR);
while((in_str=in.readLine())!=null)
{
System.out.println("Server "+in_str);
message=new BufferedReader(new InputStreamReader(System.in));
System.out.flush();
System.out.print("Send:");
out_str=message.readLine();
if (out_str!=null)out.println(out_str);
else break;
}
System.out.println("Conection canceled...");
out.close();
in.close();
message.close();
SSLsocket.close();
System.exit(1);
}catch(IOException e)
{
System.out.println("Error:"+e.getMessage());
try{
out.close();
in.close();
message.close();
SSLsocket.close();
System.exit(1);
}catch(IOException ex)
{System.out.println("Error:"+ex.getMessage());}
}
}
}
public class SSLClientSide{
public static void main(String[] args){
System.setProperty("javax.net.ssl.trustStore","SSLcert");
System.setProperty("javax.net.ssl.trustStorePassword","e1002qa2");
contact_server t=new contact_server();
t.send_message();
}
}
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|