/* * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * performs a simple exchange of data between the two sockets * and throws an exception if there is any problem.
*/ publicstaticvoid simpleDataExchange (Socket s1, Socket s2) throws Exception {
/** * Send a packet from s1 to s2 (ia2/s2.localPort) and check it * Send a packet from s2 to s1 (ia1/s1.localPort) and check it
*/ publicstaticvoid simpleDataExchange (DatagramSocket s1, InetAddress ia1,
DatagramSocket s2, InetAddress ia2) throws Exception {
byte[] b1 = p1.getData(); byte[] b2 = p2.getData(); int len = p1.getLength () > p2.getLength() ? p2.getLength()
: p1.getLength(); for (int i=0; i<len; i++) { if (b1[i] != b2[i]) { thrownew Exception ("packets not the same");
}
}
}
/* check the time got is within 50% of the time expected */ publicstaticvoid checkTime (long got, long expected) {
checkTime(got, expected, expected);
}
/* check the time got is between start and end, given 50% tolerance */ publicstaticvoid checkTime(long got, long start, long end) {
dprintln("checkTime: got = " + got + " start = " + start + " end = " + end); long upper = end + (end / 2); long lower = start - (start / 2); if (got > upper || got < lower) { thrownew RuntimeException("checkTime failed: got " + got
+ ", expected between " + start + " and " + end);
}
}
/* * Take the given Runnable and run it in a spawned thread * after the given time has elapsed. runAfter() returns immediately
*/ publicstaticvoid runAfter (long millis, Runnable runnee) {
Runner runner = new Runner (runnee, millis);
runner.start ();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.