Example #1
0
  /*
   * Define the server side of the test.
   *
   * If the server prematurely exits, serverReady will be set to true
   * to avoid infinite hangs.
   */
  void doServerSide() throws Exception {
    // create SSLEngine.
    SSLEngine ssle = createSSLEngine(false);

    // Create a server socket channel.
    InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), serverPort);
    ServerSocketChannel ssc = ServerSocketChannel.open();
    ssc.socket().bind(isa);
    serverPort = ssc.socket().getLocalPort();

    // Signal Client, we're ready for his connect.
    serverReady = true;

    // Accept a socket channel.
    SocketChannel sc = ssc.accept();

    // Complete connection.
    while (!sc.finishConnect()) {
      // waiting for the connection completed.
    }

    // handshaking
    handshaking(ssle, sc, null);

    // receive application data
    receive(ssle, sc);

    // send out application data
    deliver(ssle, sc);

    // close the socket channel.
    sc.close();
    ssc.close();
  }
Example #2
0
  /*
   * Define the client side of the test.
   *
   * If the server prematurely exits, serverReady will be set to true
   * to avoid infinite hangs.
   */
  void doClientSide() throws Exception {
    // create SSLEngine.
    SSLEngine ssle = createSSLEngine(true);

    /*
     * Wait for server to get started.
     */
    while (!serverReady) {
      Thread.sleep(50);
    }

    // Create a non-blocking socket channel.
    SocketChannel sc = SocketChannel.open();
    sc.configureBlocking(false);
    InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), serverPort);
    sc.connect(isa);

    // Complete connection.
    while (!sc.finishConnect()) {
      // waiting for the connection completed.
    }

    // handshaking
    handshaking(ssle, sc, null);

    // send out application data
    deliver(ssle, sc);

    // receive application data
    receive(ssle, sc);

    // close the socket channel.
    sc.close();
  }