expose socket instead of stream to allow two-way communication easily
authorAleš Křenek <ljocha@ics.muni.cz>
Wed, 13 May 2009 15:01:00 +0000 (15:01 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Wed, 13 May 2009 15:01:00 +0000 (15:01 +0000)
org.glite.lb.client-java/examples/SSLServer.java
org.glite.lb.client-java/src/org/glite/lb/SSL.java
org.glite.lb.client-java/src/org/glite/lb/SSLSend.java

index 573ee03..cae699e 100644 (file)
@@ -1,5 +1,6 @@
 import org.glite.lb.SSL;
 import java.io.*;
+import java.net.Socket;
 
 public class SSLServer {
        public static void main(String[] args) {
@@ -8,13 +9,16 @@ public class SSLServer {
 
                try {
                        ssl.setProxy(args[0]);
-                       InputStream in = ssl.accept(Integer.parseInt(args[1]),100000);
+                       Socket sock = ssl.accept(Integer.parseInt(args[1]),100000);
                        System.out.println("accept ok");
+                       InputStream in = sock.getInputStream();
+                       PrintStream out = new PrintStream(sock.getOutputStream(),false);
 
                        while (true) {
                                byte[] buf = new byte[1000];
                                int     len = in.read(buf);
                                System.out.write(buf,0,len);
+                               out.print("buzz off");
                        }
                }
                catch (Exception e) {
index 8b8da53..f185c6c 100644 (file)
@@ -41,8 +41,8 @@ public class SSL {
 
         public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket
 socket) {
-            System.out.println("MyX509KeyManager.chooseClientAlias()");
 /*
+            System.out.println("MyX509KeyManager.chooseClientAlias()");
             for (int i = 0; i < keyType.length; i++) {
                 System.out.println("MyX509KeyManager.chooseClientAlias() keyType[" + i +
 "]=" + keyType[i]);
@@ -140,7 +140,7 @@ socket) {
            proxy = p;
     }
 
-    public PrintStream connect(String host,int port,int timeout) throws KeyStoreException,NoSuchAlgorithmException,KeyManagementException,SocketException,IOException {
+    public Socket connect(String host,int port,int timeout) throws KeyStoreException,NoSuchAlgorithmException,KeyManagementException,SocketException,IOException {
 
            init_ctx();
            
@@ -158,10 +158,11 @@ socket) {
                 throw new NullPointerException("null session");
             }
 
-           return new PrintStream(client.getOutputStream(),false);
+           return client;
+           //return new PrintStream(client.getOutputStream(),false);
     }
 
-    public InputStream accept(int port,int timeout) 
+    public Socket accept(int port,int timeout) 
            throws KeyStoreException,IOException,SocketException,NoSuchAlgorithmException,KeyManagementException
     {
 
@@ -176,7 +177,7 @@ socket) {
 
        SSLSocket conn = (SSLSocket) server.accept();
 
-       return conn.getInputStream();
+       return conn;
     }
 
     public void close() throws IOException,SocketException {
index 13711d5..b687762 100644 (file)
@@ -3,6 +3,7 @@ package org.glite.lb;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.security.*;
+import java.net.Socket;
 
 /**
  * This class opens secure connection using SSLv3 and then sends message to set
@@ -31,7 +32,8 @@ public class SSLSend {
        SSL lbsock = new SSL();
 
        lbsock.setProxy(keyStoreSender);
-       PrintStream s = lbsock.connect(host,port,timeout);
+       Socket sock = lbsock.connect(host,port,timeout);
+       PrintStream s = new PrintStream(sock.getOutputStream(),false);
 
         s.print(EDG_WLL_LOG_SOCKET_HEADER);