< prev index next >

test/jdk/sun/security/ssl/SSLSocketImpl/NewSocketMethods.java

Print this page
rev 59383 : [mq]: final
   1 /*
   2  * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 186                 (SSLSocketFactory) SSLSocketFactory.getDefault();
 187             Socket plainSocket = new Socket("localhost", serverPort);
 188             socket = (SSLSocket)
 189                 sslsf.createSocket(plainSocket, "localhost", serverPort, true);
 190         }
 191         else
 192             socket = new Socket("localhost", serverPort);
 193         try {
 194             InputStream is = socket.getInputStream();
 195             OutputStream os = socket.getOutputStream();
 196 
 197             /**
 198              * test some new methods of java.net.Socket added to merlin.
 199              */
 200             System.out.println("Client isInputShutdown() "
 201                         + socket.isInputShutdown());
 202             socket.setReuseAddress(true);
 203             System.out.println("Client getReuseAddress(): "
 204                         + socket.getReuseAddress());
 205 
 206             // Solaris does not support set/get of IPV6_TCLASS when connected
 207             if (!"SunOS".equals(System.getProperty("os.name"))) {
 208                 socket.setTrafficClass(8);
 209                 System.out.println("Client getTrafficClass(): "
 210                         + socket.getTrafficClass());
 211             }
 212 
 213             os.write(237);
 214             os.flush();
 215             System.out.println("Client read: " + is.read());
 216             socket.close();
 217             System.out.println("Client isOutputShutdown() "
 218                         + socket.isOutputShutdown());
 219         } catch (Exception unexpected) {
 220             throw new Exception(" test failed, caught exception: "
 221                         + unexpected);
 222           }
 223     }
 224 
 225     /*
 226      * =============================================================
 227      * The remainder is just support stuff
 228      */
 229 
 230     // use any free port by default
 231     volatile int serverPort = 0;


   1 /*
   2  * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 186                 (SSLSocketFactory) SSLSocketFactory.getDefault();
 187             Socket plainSocket = new Socket("localhost", serverPort);
 188             socket = (SSLSocket)
 189                 sslsf.createSocket(plainSocket, "localhost", serverPort, true);
 190         }
 191         else
 192             socket = new Socket("localhost", serverPort);
 193         try {
 194             InputStream is = socket.getInputStream();
 195             OutputStream os = socket.getOutputStream();
 196 
 197             /**
 198              * test some new methods of java.net.Socket added to merlin.
 199              */
 200             System.out.println("Client isInputShutdown() "
 201                         + socket.isInputShutdown());
 202             socket.setReuseAddress(true);
 203             System.out.println("Client getReuseAddress(): "
 204                         + socket.getReuseAddress());
 205 


 206             socket.setTrafficClass(8);
 207             System.out.println("Client getTrafficClass(): "
 208                     + socket.getTrafficClass());

 209 
 210             os.write(237);
 211             os.flush();
 212             System.out.println("Client read: " + is.read());
 213             socket.close();
 214             System.out.println("Client isOutputShutdown() "
 215                         + socket.isOutputShutdown());
 216         } catch (Exception unexpected) {
 217             throw new Exception(" test failed, caught exception: "
 218                         + unexpected);
 219           }
 220     }
 221 
 222     /*
 223      * =============================================================
 224      * The remainder is just support stuff
 225      */
 226 
 227     // use any free port by default
 228     volatile int serverPort = 0;


< prev index next >