use of java.net.DatagramSocket in project jdk8u_jdk by JetBrains.
the class BadKdc method go0.
public static void go0(String... expected) throws Exception {
System.setProperty("sun.security.krb5.debug", "true");
// Idle UDP sockets will trigger a SocketTimeoutException, without it,
// a PortUnreachableException will be thrown.
DatagramSocket d1 = null, d2 = null, d3 = null;
// Make sure KDCs' ports starts with 1 and 2 and 3,
// useful for checking debug output.
int p1 = 10000 + new java.util.Random().nextInt(10000);
int p2 = 20000 + new java.util.Random().nextInt(10000);
int p3 = 30000 + new java.util.Random().nextInt(10000);
FileWriter fw = new FileWriter("alternative-krb5.conf");
fw.write("[libdefaults]\n" + "default_realm = " + OneKDC.REALM + "\n" + "kdc_timeout = " + toReal(2000) + "\n");
fw.write("[realms]\n" + OneKDC.REALM + " = {\n" + "kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" + "kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" + "kdc = " + OneKDC.KDCHOST + ":" + p3 + "\n" + "}\n");
fw.close();
System.setProperty("java.security.krb5.conf", "alternative-krb5.conf");
Config.refresh();
// Turn on k3 only
d1 = new DatagramSocket(p1);
d2 = new DatagramSocket(p2);
KDC k3 = on(p3);
test(expected[0]);
test(expected[1]);
Config.refresh();
test(expected[2]);
// shutdown k3
k3.terminate();
d3 = new DatagramSocket(p3);
d2.close();
// k2 is on
on(p2);
test(expected[3]);
d1.close();
// k1 and k2 is on
on(p1);
test(expected[4]);
d3.close();
}
use of java.net.DatagramSocket in project jdk8u_jdk by JetBrains.
the class DatagramTimeout method main.
public static void main(String[] args) throws Exception {
boolean success = false;
DatagramSocket sock = new DatagramSocket();
try {
DatagramPacket p;
byte[] buffer = new byte[50];
p = new DatagramPacket(buffer, buffer.length);
sock.setSoTimeout(2);
sock.receive(p);
} catch (SocketTimeoutException e) {
success = true;
} finally {
sock.close();
}
if (!success)
throw new RuntimeException("Socket timeout failure.");
}
use of java.net.DatagramSocket in project jdk8u_jdk by JetBrains.
the class LocalSocketAddress method main.
public static void main(String[] args) throws SocketException {
InetAddress IPv6LoopbackAddr = null;
DatagramSocket soc = null;
try {
List<NetworkInterface> nics = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nic : nics) {
if (!nic.isLoopback())
continue;
List<InetAddress> addrs = Collections.list(nic.getInetAddresses());
for (InetAddress addr : addrs) {
if (addr instanceof Inet6Address) {
IPv6LoopbackAddr = addr;
break;
}
}
}
if (IPv6LoopbackAddr == null) {
System.out.println("IPv6 is not available, exiting test.");
return;
}
soc = new DatagramSocket(0, IPv6LoopbackAddr);
if (!IPv6LoopbackAddr.equals(soc.getLocalAddress())) {
throw new RuntimeException("Bound address is " + soc.getLocalAddress() + ", but should be " + IPv6LoopbackAddr);
}
} finally {
if (soc != null) {
soc.close();
}
}
}
use of java.net.DatagramSocket in project jdk8u_jdk by JetBrains.
the class PortUnreachable method execute.
void execute() throws Exception {
// pick a port for the server
DatagramSocket sock2 = new DatagramSocket();
serverPort = sock2.getLocalPort();
// send a burst of packets to the unbound port - we should get back
// icmp port unreachable messages
//
InetAddress addr = InetAddress.getLocalHost();
byte[] b = "Hello me".getBytes();
DatagramPacket packet = new DatagramPacket(b, b.length, addr, serverPort);
//close just before sending
sock2.close();
for (int i = 0; i < 100; i++) clientSock.send(packet);
serverSend();
// try to receive
b = new byte[25];
packet = new DatagramPacket(b, b.length, addr, serverPort);
clientSock.setSoTimeout(10000);
clientSock.receive(packet);
System.out.println("client received data packet " + new String(packet.getData()));
// done
clientSock.close();
}
use of java.net.DatagramSocket in project jdk8u_jdk by JetBrains.
the class SendSize method main.
public static void main(String[] args) throws Exception {
DatagramSocket serverSocket = new DatagramSocket();
new ServerThread(serverSocket).start();
new ClientThread(serverSocket.getLocalPort()).start();
}
Aggregations