equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2018, 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. |
39 import java.io.IOException; |
39 import java.io.IOException; |
40 import java.net.DatagramPacket; |
40 import java.net.DatagramPacket; |
41 import java.net.DatagramSocket; |
41 import java.net.DatagramSocket; |
42 import java.net.DatagramSocketImpl; |
42 import java.net.DatagramSocketImpl; |
43 import java.net.InetAddress; |
43 import java.net.InetAddress; |
|
44 import java.net.InetSocketAddress; |
44 import java.net.MulticastSocket; |
45 import java.net.MulticastSocket; |
45 import java.net.UnknownHostException; |
46 import java.net.UnknownHostException; |
46 import java.nio.file.Files; |
47 import java.nio.file.Files; |
47 import java.nio.file.Path; |
48 import java.nio.file.Path; |
48 import java.nio.file.Paths; |
49 import java.nio.file.Paths; |
71 static class Server implements Runnable { |
72 static class Server implements Runnable { |
72 |
73 |
73 MulticastSocket ss; |
74 MulticastSocket ss; |
74 |
75 |
75 Server() throws IOException { |
76 Server() throws IOException { |
76 ss = new MulticastSocket(0); |
77 InetSocketAddress serverAddress = |
|
78 new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); |
|
79 ss = new MulticastSocket(serverAddress); |
77 System.out.printf(" DatagramServer addr: %s: %d%n", |
80 System.out.printf(" DatagramServer addr: %s: %d%n", |
78 this.getHost(), this.getPort()); |
81 this.getHost(), this.getPort()); |
79 pendingSockets.add(new NamedWeak(ss, pendingQueue, "serverMulticastSocket")); |
82 pendingSockets.add(new NamedWeak(ss, pendingQueue, "serverMulticastSocket")); |
80 extractRefs(ss, "serverMulticastSocket"); |
83 extractRefs(ss, "serverMulticastSocket"); |
81 } |
84 } |
82 |
85 |
83 InetAddress getHost() throws UnknownHostException { |
86 InetAddress getHost() throws UnknownHostException { |
84 InetAddress localhost = InetAddress.getByName("localhost"); //.getLocalHost(); |
87 InetAddress localhost = InetAddress.getLoopbackAddress(); |
85 return localhost; |
88 return localhost; |
86 } |
89 } |
87 |
90 |
88 int getPort() { |
91 int getPort() { |
89 return ss.getLocalPort(); |
92 return ss.getLocalPort(); |