< prev index next >

test/java/nio/channels/spi/SelectorProvider/inheritedChannel/EchoTest.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2010, 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  */
  23 
  24 /*
  25  *
  26  *
  27  * Used in conjunction to EchoService to test System.inheritedChannel().
  28  *
  29  * The first test is the TCP echo test. A service is launched with a TCP
  30  * socket and a TCP message is sent to the service. The test checks that
  31  * the message is correctly echoed.
  32  *
  33  * The second test is a UDP echo test. A service is launched with a UDP
  34  * socket and a UDP packet is sent to the service. The test checks that
  35  * the packet is correctly echoed.
  36  *
  37  */
  38 import java.net.*;
  39 import java.io.*;
  40 import java.nio.ByteBuffer;
  41 import java.nio.channels.*;



  42 import java.util.Random;
  43 
  44 public class EchoTest {
  45 
  46     private static int failures = 0;
  47 
  48     private static String ECHO_SERVICE = "EchoService";
  49 
  50     /*
  51      * Sends a message with random bytes to the service, and then waits for
  52      * a reply (with timeout). Once the reply is received it is checked to ensure
  53      * that it matches the original message.
  54      */
  55     private static void TCPEchoTest() throws IOException {
  56         SocketChannel sc = Launcher.launchWithSocketChannel(ECHO_SERVICE, null);
  57 
  58         String msg = "Where's that damn torpedo?";
  59         int repeat = 100;
  60         int size = msg.length() * repeat;
  61 


   1 /*
   2  * Copyright (c) 2003, 2017, 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  */
  23 
  24 /*
  25  *
  26  *
  27  * Used in conjunction to EchoService to test System.inheritedChannel().
  28  *
  29  * The first test is the TCP echo test. A service is launched with a TCP
  30  * socket and a TCP message is sent to the service. The test checks that
  31  * the message is correctly echoed.
  32  *
  33  * The second test is a UDP echo test. A service is launched with a UDP
  34  * socket and a UDP packet is sent to the service. The test checks that
  35  * the packet is correctly echoed.
  36  *
  37  */
  38 import java.io.IOException;
  39 import java.net.DatagramPacket;
  40 import java.nio.ByteBuffer;
  41 import java.nio.channels.DatagramChannel;
  42 import java.nio.channels.SelectionKey;
  43 import java.nio.channels.Selector;
  44 import java.nio.channels.SocketChannel;
  45 import java.util.Random;
  46 
  47 public class EchoTest {
  48 
  49     private static int failures = 0;
  50 
  51     private static String ECHO_SERVICE = "EchoService";
  52 
  53     /*
  54      * Sends a message with random bytes to the service, and then waits for
  55      * a reply (with timeout). Once the reply is received it is checked to ensure
  56      * that it matches the original message.
  57      */
  58     private static void TCPEchoTest() throws IOException {
  59         SocketChannel sc = Launcher.launchWithSocketChannel(ECHO_SERVICE, null);
  60 
  61         String msg = "Where's that damn torpedo?";
  62         int repeat = 100;
  63         int size = msg.length() * repeat;
  64 


< prev index next >