Skip to content
Snippets Groups Projects
Commit 8c455492 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

rename for clarity

parent 8ebf7f5e
No related branches found
No related tags found
No related merge requests found
Showing
with 106 additions and 87 deletions
package UdpMulticastExamples;
package UdpExamples;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import java.io.*;
......@@ -13,7 +13,7 @@ import java.util.logging.Logger;
* @author mcgredo
* @author brutzman
*/
public class MulticastReceiver {
public class MulticastUdpReceiver {
// reserved range for all IPv4 multicast: 224.0.0.0 through 239.255.255.255
// https://en.wikipedia.org/wiki/Multicast_address
......@@ -41,7 +41,7 @@ public class MulticastReceiver {
DatagramPacket packet = new DatagramPacket(buffer.array(), buffer.capacity());
try {
System.out.println("MulticastReceiver started...");
System.out.println("UdpMulticastExamples.MulticastUdpReceiver started...");
// This is a java/IPv6 problem. You should also add it to the
// arguments used to start the app, eg -Djava.net.preferIPv4Stack=true
......@@ -78,8 +78,8 @@ public class MulticastReceiver {
nextChar = buffer.getChar();
firstCharacters.append(nextChar);
}
if (firstCharacters.toString().contains(MulticastSender.QUIT_SENTINEL)) {
System.out.println("Received sentinel \"" + MulticastSender.QUIT_SENTINEL + "\"");
if (firstCharacters.toString().contains(MulticastUdpSender.QUIT_SENTINEL)) {
System.out.println("Received sentinel \"" + MulticastUdpSender.QUIT_SENTINEL + "\"");
if (!INFINITE_READ_LOOP) {
break; // exit out of reading loop
}
......@@ -107,7 +107,7 @@ public class MulticastReceiver {
try {
multicastSocket.leaveGroup(group, ni);
} catch (IOException ex) {
Logger.getLogger(MulticastReceiver.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(MulticastUdpReceiver.class.getName()).log(Level.SEVERE, null, ex);
}
multicastSocket.close();
}
......
package UdpMulticastExamples;
package UdpExamples;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import java.io.*;
......@@ -14,7 +14,7 @@ import java.util.logging.Logger;
* @author mcgredo
* @author brutzman
*/
public class MulticastSender
public class MulticastUdpSender
{
// reserved range for all IPv4 multicast: 224.0.0.0 through 239.255.255.255
// https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml
......@@ -56,7 +56,7 @@ public class MulticastSender
try
{
System.out.println("MulticastSender started...");
System.out.println("UdpMulticastExamples.MulticastUdpSender started...");
// This is a java/IPv6 problem. You should also add it to the
// arguments used to start the app, eg -Djava.net.preferIPv4Stack=true
// set in the "run" section of preferences. Also, typically
......@@ -95,7 +95,7 @@ public class MulticastSender
buffer = baos.toByteArray();
packet.setData(buffer);
multicastSocket.send(packet);
System.out.println("Sent multicast packet " + index + " of " + LOOPSIZE);
System.out.println("Sent multicast packet " + (index + 1) + " of " + LOOPSIZE);
baos.reset();
// How fast does this go? Does UDP try to slow it down, or does
......@@ -117,7 +117,7 @@ public class MulticastSender
try {
multicastSocket.leaveGroup(group, ni);
} catch (IOException ex) {
Logger.getLogger(MulticastSender.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(MulticastUdpSender.class.getName()).log(Level.SEVERE, null, ex);
}
multicastSocket.close();
}
......
examples/src/UdpExamples/MulticastUdpSenderWireshark.png

199 KiB

Invocation instructions:
1. run/debug MulticastReceiver.java
2. run/debug MulticastSender.java
Program responses follow for sender and receiver:
===================================================
UdpMulticastExamples.MulticastUdpSender started...
Multicast address/port: 239.1.2.15/1718
[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] Using network interface Intel(R) Centrino(R) Ultimate-N 6300 AGN
Sent multicast packet 1 of 20
Sent multicast packet 2 of 20
Sent multicast packet 3 of 20
Sent multicast packet 4 of 20
Sent multicast packet 5 of 20
Sent multicast packet 6 of 20
Sent multicast packet 7 of 20
Sent multicast packet 8 of 20
Sent multicast packet 9 of 20
Sent multicast packet 10 of 20
Sent multicast packet 11 of 20
Sent multicast packet 12 of 20
Sent multicast packet 13 of 20
Sent multicast packet 14 of 20
Sent multicast packet 15 of 20
Sent multicast packet 16 of 20
Sent multicast packet 17 of 20
Sent multicast packet 18 of 20
Sent multicast packet 19 of 20
Sent multicast packet 20 of 20
MulticastSender complete.
BUILD SUCCESSFUL (total time: 22 seconds)
===================================================
run:
UdpMulticastExamples.MulticastUdpReceiver started...
[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] Using network interface Intel(R) Centrino(R) Ultimate-N 6300 AGN
Multicast address/port: 239.1.2.15/1718
Multicast packets received log:
1. "From don: MulticastSender packet 0;" index=0, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
2. "From don: MulticastSender packet 1;" index=1, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
3. "From don: MulticastSender packet 2;" index=2, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
4. "From don: MulticastSender packet 3;" index=3, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
5. "From don: MulticastSender packet 4;" index=4, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
6. "From don: MulticastSender packet 5;" index=5, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
7. "From don: MulticastSender packet 6;" index=6, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
8. "From don: MulticastSender packet 7;" index=7, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
9. "From don: MulticastSender packet 8;" index=8, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
10. "From don: MulticastSender packet 9;" index=9, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
11. "From don: MulticastSender packet 10;" index=10, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
12. "From don: MulticastSender packet 11;" index=11, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
13. "From don: MulticastSender packet 12;" index=12, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
14. "From don: MulticastSender packet 13;" index=13, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
15. "From don: MulticastSender packet 14;" index=14, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
16. "From don: MulticastSender packet 15;" index=15, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
17. "From don: MulticastSender packet 16;" index=16, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
18. "From don: MulticastSender packet 17;" index=17, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
19. "From don: MulticastSender packet 18;" index=18, firstFloat=17.0 secondFloat=23.0
MulticastReceiver loop complete.
Received sentinel "QUIT QUIT QUIT!"
20. "QUIT QUIT QUIT!;" index=6357107, firstFloat=1.0653034E-38 secondFloat=9.275539E-39
MulticastReceiver loop complete.
===================================================
package UdpMulticastExamples;
package UdpExamples;
import java.io.*;
import java.net.*;
......@@ -16,7 +16,7 @@ import java.net.*;
* @author mcgredo
* @author brutzman
*/
public class UdpReceiver
public class UnicastUdpReceiver
{
// public static final int SENDING_PORT = 1414; // port used by UdpSender, unneeded here
/** socket value of shared interest */
......@@ -34,7 +34,7 @@ public class UdpReceiver
try
{
System.out.println(UdpReceiver.class.getName() + " started...");
System.out.println(UnicastUdpReceiver.class.getName() + " started...");
// Create a UDP socket
udpSocket = new DatagramSocket(UDP_PORT);
......@@ -80,7 +80,7 @@ public class UdpReceiver
padding = " ";
else padding = "";
System.out.println("[" + UdpReceiver.class.getName() + "]" +
System.out.println("[" + UnicastUdpReceiver.class.getName() + "]" +
" port=" + UDP_PORT +
" packetID=" + firstInt + // have output message use same name as sender
", second float value=" + secondFloat +
......@@ -98,7 +98,7 @@ public class UdpReceiver
{
if (udpSocket != null)
udpSocket.close();
System.out.println(UdpReceiver.class.getName() + " complete."); // all done
System.out.println(UnicastUdpReceiver.class.getName() + " complete."); // all done
}
}
}
package UdpMulticastExamples;
package UdpExamples;
import java.io.*;
import java.net.*;
......@@ -17,12 +17,12 @@ import java.net.*;
* @author mcgredo
* @author brutzman
*/
public class UdpSender
public class UnicastUdpSender
{
private static final String MY_NAME = System.getProperty("user.name"); // guru incantation 8)
// public static final int SENDING_PORT = 1414; // not needed, can let system choose an open local port
/** socket value of shared interest */
public static final int UDP_PORT = UdpReceiver.UDP_PORT; // 1415; ensure consistent
public static final int UDP_PORT = UnicastUdpReceiver.UDP_PORT; // 1415; ensure consistent
private static final int TOTAL_PACKETS_TO_SEND = 100;
/** socket value of shared interest */
......@@ -46,8 +46,8 @@ public class UdpSender
try
{
System.out.println(UdpSender.class.getName() + " shows how to send simple-type values via DataOutputStream");
System.out.println(UdpSender.class.getName() + " started...");
System.out.println(UnicastUdpSender.class.getName() + " shows how to send simple-type values via DataOutputStream");
System.out.println(UnicastUdpSender.class.getName() + " started...");
// Create a UDP socket
udpSocket = new DatagramSocket(); // let system assign output port, then SENDING_PORT not needed
......@@ -100,7 +100,7 @@ public class UdpSender
else padding = "";
Thread.sleep(100); // Send packets at rate of one per second
System.out.println("[" + UdpSender.class.getName() + "] " + MY_NAME + " " + sourceAddress +
System.out.println("[" + UnicastUdpSender.class.getName() + "] " + MY_NAME + " " + sourceAddress +
" port=" + UDP_PORT +
" has sent values (" + packetID + "," + value + ",\"" + message + "\"," + isPacketIdEvenParity +
")" + padding + " as packet #" + index + " of " + TOTAL_PACKETS_TO_SEND);
......@@ -126,7 +126,7 @@ public class UdpSender
System.err.println("Problem with UdpSender, see exception trace:");
System.err.println(e);
}
System.out.println(UdpSender.class.getName() + " complete."); // all done
System.out.println(UnicastUdpSender.class.getName() + " complete."); // all done
}
}
}
......@@ -6,4 +6,4 @@
* @see <a href="https://stackoverflow.com/questions/624422/how-do-i-document-packages-in-java">https://stackoverflow.com/questions/624422/how-do-i-document-packages-in-java</a>
*/
package UdpMulticastExamples;
package UdpExamples;
Invocation instructions:
1. run/debug MulticastReceiver.java
2. run/debug MulticastSender.java
Program responses:
===================================================
run:
MulticastSender started...
Multicast address/port: 239.1.2.15/1718
Sent multicast packet 0 of 20
Sent multicast packet 1 of 20
Sent multicast packet 2 of 20
Sent multicast packet 3 of 20
Sent multicast packet 4 of 20
Sent multicast packet 5 of 20
Sent multicast packet 6 of 20
Sent multicast packet 7 of 20
Sent multicast packet 8 of 20
Sent multicast packet 9 of 20
Sent multicast packet 10 of 20
Sent multicast packet 11 of 20
Sent multicast packet 12 of 20
Sent multicast packet 13 of 20
Sent multicast packet 14 of 20
Sent multicast packet 15 of 20
Sent multicast packet 16 of 20
Sent multicast packet 17 of 20
Sent multicast packet 18 of 20
Sent multicast packet 19 of 20
MulticastSender complete.
BUILD SUCCESSFUL (total time: 20 seconds)
===================================================
run:
MulticastReceiver started...
Multicast address/port: 239.1.2.15/1718
Multicast packets received log:
1. "MulticastSender packet 0;" index=0, firstFloat=17.0 secondFloat=23.0
2. "MulticastSender packet 1;" index=1, firstFloat=17.0 secondFloat=23.0
3. "MulticastSender packet 2;" index=2, firstFloat=17.0 secondFloat=23.0
4. "MulticastSender packet 3;" index=3, firstFloat=17.0 secondFloat=23.0
5. "MulticastSender packet 4;" index=4, firstFloat=17.0 secondFloat=23.0
6. "MulticastSender packet 5;" index=5, firstFloat=17.0 secondFloat=23.0
7. "MulticastSender packet 6;" index=6, firstFloat=17.0 secondFloat=23.0
8. "MulticastSender packet 7;" index=7, firstFloat=17.0 secondFloat=23.0
9. "MulticastSender packet 8;" index=8, firstFloat=17.0 secondFloat=23.0
10. "MulticastSender packet 9;" index=9, firstFloat=17.0 secondFloat=23.0
11. "MulticastSender packet 10;" index=10, firstFloat=17.0 secondFloat=23.0
12. "MulticastSender packet 11;" index=11, firstFloat=17.0 secondFloat=23.0
13. "MulticastSender packet 12;" index=12, firstFloat=17.0 secondFloat=23.0
14. "MulticastSender packet 13;" index=13, firstFloat=17.0 secondFloat=23.0
15. "MulticastSender packet 14;" index=14, firstFloat=17.0 secondFloat=23.0
16. "MulticastSender packet 15;" index=15, firstFloat=17.0 secondFloat=23.0
17. "MulticastSender packet 16;" index=16, firstFloat=17.0 secondFloat=23.0
18. "MulticastSender packet 17;" index=17, firstFloat=17.0 secondFloat=23.0
19. "MulticastSender packet 18;" index=18, firstFloat=17.0 secondFloat=23.0
Received "quit;" sentinel
MulticastReceiver loop complete.
MulticastReceiver finally block, complete.
BUILD SUCCESSFUL (total time: 31 seconds)
===================================================
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment