added SSL
[org.ibex.net.git] / src / org / ibex / net / ssl / Test.java
diff --git a/src/org/ibex/net/ssl/Test.java b/src/org/ibex/net/ssl/Test.java
new file mode 100644 (file)
index 0000000..aa43ccb
--- /dev/null
@@ -0,0 +1,32 @@
+package org.ibex.net.ssl;
+
+import org.ibex.net.SSL;
+import java.io.*;
+
+public class Test {
+    public static void main(String[] args) throws Exception {
+        SSL.debugOn = true;
+        if(args.length < 2) { System.err.println("Usage: SSL host port"); }
+        String host = args[0];
+        int port = Integer.parseInt(args[1]);
+        SSL ssl = new SSL(host,port);
+        //ssl.setTLS(false);
+        ssl.getOutputStream().write(SSL.getBytes("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n"));
+        cat(ssl.getInputStream());
+        ssl.close();
+        
+        // try to resume
+        ssl = new SSL(host,port,ssl.getSessionState());
+        ssl.getOutputStream().write(SSL.getBytes("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n"));
+        cat(ssl.getInputStream());
+        ssl.close();
+    }
+    private static void cat(InputStream is) throws IOException {
+        BufferedReader br = new BufferedReader(new InputStreamReader(is));
+        String line;
+        int count = 100;
+        try {
+            while((line = br.readLine()) != null && --count >= 0) System.out.println(line);
+        } catch(SSL.PrematureCloseExn e) { /* ignore */ }
+    }
+}