equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
36 |
36 |
37 static class ServerThread extends Thread{ |
37 static class ServerThread extends Thread{ |
38 DatagramSocket ds; |
38 DatagramSocket ds; |
39 public ServerThread() { |
39 public ServerThread() { |
40 try { |
40 try { |
41 ds = new DatagramSocket(); |
41 InetAddress local = InetAddress.getLocalHost(); |
|
42 InetSocketAddress bindaddr = new InetSocketAddress(local, 0); |
|
43 ds = new DatagramSocket(bindaddr); |
42 port = ds.getLocalPort(); |
44 port = ds.getLocalPort(); |
43 } catch (Exception e) { |
45 } catch (Exception e) { |
44 throw new RuntimeException(e.getMessage()); |
46 throw new RuntimeException(e.getMessage()); |
45 } |
47 } |
46 } |
48 } |
66 } |
68 } |
67 |
69 |
68 public static void main(String args[]) throws Exception { |
70 public static void main(String args[]) throws Exception { |
69 ServerThread st = new ServerThread(); |
71 ServerThread st = new ServerThread(); |
70 st.start(); |
72 st.start(); |
71 DatagramSocket ds = new DatagramSocket(); |
73 InetAddress local = InetAddress.getLocalHost(); |
|
74 InetSocketAddress bindaddr = new InetSocketAddress(local, 0); |
|
75 DatagramSocket ds = new DatagramSocket(bindaddr); |
72 byte b[] = new byte[100]; |
76 byte b[] = new byte[100]; |
73 DatagramPacket dp = new DatagramPacket(b,b.length); |
77 DatagramPacket dp = new DatagramPacket(b,b.length); |
74 for (int i = 0; i < msgs.length; i++) { |
78 for (int i = 0; i < msgs.length; i++) { |
75 ds.send(new DatagramPacket(msgs[i].getBytes(),msgs[i].length(), |
79 ds.send(new DatagramPacket(msgs[i].getBytes(),msgs[i].length(), |
76 InetAddress.getLocalHost(), |
80 InetAddress.getLocalHost(), |