import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.security.*; import javax.net.ssl.*; //import java.util.*; public class Client extends JFrame implements Runnable { private Thread thread = new Thread(this); private Socket socket; private static String host = "127.0.0.1"; private static int port = 2000; private static boolean visible = true; private JTextField textField = new JTextField(); private JTextArea textArea = new JTextArea(); public static void main(String args[]) { if(args.length != 0) { host = args[0]; if(args.length != 1) { port = Integer.parseInt(args[1]); } } new Client(); } public Client() { textField.addActionListener(new L2()); getContentPane().add("North", textField); getContentPane().add("Center", new JScrollPane(textArea)); setLocation(420, 0); setSize(400, 200); addWindowListener(new L1()); show(); try { //Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); SSLSocketFactory sslSF = (SSLSocketFactory)SSLSocketFactory.getDefault(); socket =(SSLSocket)sslSF.createSocket(host, port); System.out.println("CLIENT CONNECTED"); String[] cipherSuites = ((SSLSocket)socket).getEnabledCipherSuites(); System.out.println("ENABLED CIPHER SUITES:"); for(int i= 0; i < cipherSuites.length; i++) System.out.println(" " + cipherSuites[i]); String[] encs = new String[cipherSuites.length + 1]; for(int len = 0; len < cipherSuites.length; len++) encs[len] = cipherSuites[len]; encs[cipherSuites.length] = "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA"; ((SSLSocket)socket).setEnabledCipherSuites(encs); setTitle("CONNECTED TO: " + host + " - ON PORT: " + port); } catch (IOException e) { System.out.println("IOException generated" + e); System.out.println("COULD NOT CONNECT"); killMe(); } thread.start(); } public void run() { BufferedReader in = null; try{ in = new BufferedReader(new InputStreamReader(socket.getInputStream())); } catch(IOException e) { System.out.println("IOException generated" + e); killMe(); return; } String inputLine = ""; while(true) { try { inputLine = in.readLine(); } catch(NullPointerException e) { System.out.println("NullPointer generated: " + e); } catch(IOException e) { System.out.println("IOException generated 2: " + e); } textArea.append(inputLine + "\n"); textArea.setCaretPosition(textArea.getText().length()); Toolkit.getDefaultToolkit().beep(); } } private void sendMessage(String message) { try { PrintWriter out = new PrintWriter(socket.getOutputStream(), true); out.println(message); //out.close(); if(message.equals("exit")) killMe(); } catch (IOException e) { System.out.println("IOException generated" + e); } } private String getHost(Socket socket) { try { return(socket.getInetAddress().getLocalHost().getHostName()); } catch(java.net.UnknownHostException e) { System.out.println("UnknownHostException generated: " + e); return("unknown"); } } public void killMe() { dispose(); System.exit(1); } class L1 extends WindowAdapter { public void windowClosing(WindowEvent we) { dispose(); } public void windowClosed(WindowEvent we) { System.exit(1); } } class L2 implements ActionListener { public void actionPerformed(ActionEvent ae) { String message = textField.getText(); textField.setText(""); sendMessage(message); } } }