test/jdk/java/net/DatagramPacket/ReuseBuf.java
changeset 57965 ef15850629cd
parent 47216 71c04702a3d5
child 58688 2b1e684c3ce6
--- a/test/jdk/java/net/DatagramPacket/ReuseBuf.java	Wed Aug 28 20:05:43 2019 +0530
+++ b/test/jdk/java/net/DatagramPacket/ReuseBuf.java	Fri Aug 30 12:44:52 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, 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
@@ -38,7 +38,9 @@
         DatagramSocket ds;
         public ServerThread() {
             try {
-                ds = new DatagramSocket();
+                InetAddress local = InetAddress.getLocalHost();
+                InetSocketAddress bindaddr = new InetSocketAddress(local, 0);
+                ds = new DatagramSocket(bindaddr);
                 port = ds.getLocalPort();
             } catch (Exception e) {
                 throw new RuntimeException(e.getMessage());
@@ -68,7 +70,9 @@
     public static void main(String args[]) throws Exception {
         ServerThread st = new ServerThread();
         st.start();
-        DatagramSocket ds = new DatagramSocket();
+        InetAddress local = InetAddress.getLocalHost();
+        InetSocketAddress bindaddr = new InetSocketAddress(local, 0);
+        DatagramSocket ds = new DatagramSocket(bindaddr);
         byte b[] = new byte[100];
         DatagramPacket dp = new DatagramPacket(b,b.length);
         for (int i = 0; i < msgs.length; i++) {