diff --git a/assignments/nbproject/project.properties b/assignments/nbproject/project.properties index 61f390aa6f03fc2eae0d4291e0d876c3e86dfbbb..568ec09a5c643562112eac21528b813a6de3b98d 100644 --- a/assignments/nbproject/project.properties +++ b/assignments/nbproject/project.properties @@ -1,131 +1,131 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.desc=Student assignments performed as part of NPS course Networked Graphics MV3500. This course is an introduction to network communications in simulation applications. Topics include an introduction to the TCP/IP protocol stack; TCP/IP socket communications, including TCP, UDP, and multicast; and protocol design issues, with emphasis on Distributed Interactive Simulation (DIS) Protocol and High Level Architecture (HLA). Course emphasis is on creation and testing of network programming network code and web-browser applications. -application.homepage=https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/tree/master/assignments -application.splash=../..\\NetworkedGraphicsMV3500\\documentation\\images\\OpenDisSurferDude.png -application.title=NPS Networked Graphics MV3500 assignments -application.vendor=Don Brutzman -auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.modulepath=\ - ${run.modulepath} -debug.test.classpath=\ - ${run.test.classpath} -debug.test.modulepath=\ - ${run.test.modulepath} -# Files in build.classes.dir which should be excluded from distribution jar -# Avoid compilation or inclusion of student project depending on mutex libraries only available in JDK8 -# https://stackoverflow.com/questions/27906896/exclude-package-from-build-but-not-from-view-in-netbeans-8 -excludes=**/MV3500Cohort2019JulySeptember/projects/BrennenstuhlKnobelochMcCann/** -dist.archive.excludes=**/MV3500Cohort2019JulySeptember/projects/BrennenstuhlKnobelochMcCann/** - -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/Networked_Graphics_MV3500_assignments.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -file.reference.commons-io-2.6.jar=../lib/commons-io-2.6.jar -file.reference.dis-enums-1.3.jar=../lib/dis-enums-1.3.jar -file.reference.guava-28.0-jre.jar=../lib/guava-28.0-jre.jar -file.reference.open-dis7-enumerations-classes.jar=../lib/open-dis7-enumerations-classes.jar -file.reference.open-dis7-pdus-classes.jar=../lib/open-dis7-pdus-classes.jar -file.reference.open-dis_4.16.jar=../lib/open-dis_4.16.jar -includes=** -jar.archive.disabled=${jnlp.enabled} -jar.compress=false -jar.index=${jnlp.enabled} -javac.classpath=\ - ${file.reference.open-dis7-enumerations-classes.jar}:\ - ${file.reference.open-dis7-pdus-classes.jar}:\ - ${file.reference.commons-io-2.6.jar}:\ - ${file.reference.guava-28.0-jre.jar}:\ - ${file.reference.open-dis_4.16.jar}:\ - ${file.reference.dis-enums-1.3.jar} -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.external.vm=true -javac.modulepath= -javac.processormodulepath= -javac.processorpath=\ - ${javac.classpath} -javac.source=1.8 -javac.target=1.8 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.modulepath=\ - ${javac.modulepath} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=true -javadoc.encoding=${source.encoding} -javadoc.html5=false -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.reference.open-dis7-enumerations-classes.jar=../lib/open-dis7-enumerations-javadoc.jar -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle=Networked Graphics MV3500 NPS -jlink.launcher=false -jlink.launcher.name=Networked_Graphics_MV3500_assignments -jnlp.codebase.type=no.codebase -jnlp.descriptor=application -jnlp.enabled=false -jnlp.mixed.code=default -jnlp.offline-allowed=false -jnlp.signed=false -jnlp.signing= -jnlp.signing.alias= -jnlp.signing.keystore= -main.class=MV3500Cohort2020JulySeptember.homework1.WeissenbergerTcpExample1Telnet -# Optional override of default Application-Library-Allowable-Codebase attribute identifying the locations where your signed RIA is expected to be found. -manifest.custom.application.library.allowable.codebase= -# Optional override of default Caller-Allowable-Codebase attribute identifying the domains from which JavaScript code can make calls to your RIA without security prompts. -manifest.custom.caller.allowable.codebase= -# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed -manifest.custom.codebase= -# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions) -manifest.custom.permissions= -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -project.licensePath=../license.txt -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.modulepath=\ - ${javac.modulepath} -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -run.test.modulepath=\ - ${javac.test.modulepath} -source.encoding=UTF-8 -source.reference.open-dis7-enumerations-classes.jar=../lib/open-dis7-enumerations-source.jar -src.dir=src -test.src.dir=test +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.desc=Student assignments performed as part of NPS course Networked Graphics MV3500. This course is an introduction to network communications in simulation applications. Topics include an introduction to the TCP/IP protocol stack; TCP/IP socket communications, including TCP, UDP, and multicast; and protocol design issues, with emphasis on Distributed Interactive Simulation (DIS) Protocol and High Level Architecture (HLA). Course emphasis is on creation and testing of network programming network code and web-browser applications. +application.homepage=https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/tree/master/assignments +application.splash=../..\\NetworkedGraphicsMV3500\\documentation\\images\\OpenDisSurferDude.png +application.title=NPS Networked Graphics MV3500 assignments +application.vendor=Don Brutzman +auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +# Avoid compilation or inclusion of student project depending on mutex libraries only available in JDK8 +# https://stackoverflow.com/questions/27906896/exclude-package-from-build-but-not-from-view-in-netbeans-8 +excludes=**/MV3500Cohort2019JulySeptember/projects/BrennenstuhlKnobelochMcCann/** +dist.archive.excludes=**/MV3500Cohort2019JulySeptember/projects/BrennenstuhlKnobelochMcCann/** + +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Networked_Graphics_MV3500_assignments.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +file.reference.commons-io-2.6.jar=../lib/commons-io-2.6.jar +file.reference.dis-enums-1.3.jar=../lib/dis-enums-1.3.jar +file.reference.guava-28.0-jre.jar=../lib/guava-28.0-jre.jar +file.reference.open-dis7-enumerations-classes.jar=../lib/open-dis7-enumerations-classes.jar +file.reference.open-dis7-pdus-classes.jar=../lib/open-dis7-pdus-classes.jar +file.reference.open-dis_4.16.jar=../lib/open-dis_4.16.jar +includes=** +jar.archive.disabled=${jnlp.enabled} +jar.compress=false +jar.index=${jnlp.enabled} +javac.classpath=\ + ${file.reference.open-dis7-enumerations-classes.jar}:\ + ${file.reference.open-dis7-pdus-classes.jar}:\ + ${file.reference.commons-io-2.6.jar}:\ + ${file.reference.guava-28.0-jre.jar}:\ + ${file.reference.open-dis_4.16.jar}:\ + ${file.reference.dis-enums-1.3.jar} +# Space-separated list of extra javac options +javac.compilerargs=-Xlint:deprecation -Xlint:unchecked +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=16 +javac.target=16 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=true +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.reference.open-dis7-enumerations-classes.jar=../lib/open-dis7-enumerations-javadoc.jar +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle=Networked Graphics MV3500 NPS +jlink.launcher=false +jlink.launcher.name=Networked_Graphics_MV3500_assignments +jnlp.codebase.type=no.codebase +jnlp.descriptor=application +jnlp.enabled=false +jnlp.mixed.code=default +jnlp.offline-allowed=false +jnlp.signed=false +jnlp.signing= +jnlp.signing.alias= +jnlp.signing.keystore= +main.class=MV3500Cohort2020JulySeptember.homework1.WeissenbergerTcpExample1Telnet +# Optional override of default Application-Library-Allowable-Codebase attribute identifying the locations where your signed RIA is expected to be found. +manifest.custom.application.library.allowable.codebase= +# Optional override of default Caller-Allowable-Codebase attribute identifying the domains from which JavaScript code can make calls to your RIA without security prompts. +manifest.custom.caller.allowable.codebase= +# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed +manifest.custom.codebase= +# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions) +manifest.custom.permissions= +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +project.licensePath=../license.txt +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +source.reference.open-dis7-enumerations-classes.jar=../lib/open-dis7-enumerations-source.jar +src.dir=src +test.src.dir=test diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/AngelMulticastReceiver.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/AngelMulticastReceiver.java index 407c3c3ab8f6db37940a3d7f98ff35c3fec1da55..ea1378056c80ac8de37edaeaa9c609b21bdf24ac 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/AngelMulticastReceiver.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/AngelMulticastReceiver.java @@ -17,7 +17,7 @@ public class AngelMulticastReceiver { /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; /** run the program * @param args command-line arguments, string parameters (unused) */ diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/AngelMulticastSenderExample.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/AngelMulticastSenderExample.java index 36da85088b2648f5a09b23e8266013fdd874e7b7..e52746069583323bb9edbf616d15f0e6f13612d9 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/AngelMulticastSenderExample.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/AngelMulticastSenderExample.java @@ -19,7 +19,7 @@ public class AngelMulticastSenderExample { /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; /** run the program * @param args command-line arguments, string parameters (unused) */ diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/BlankenbekerMulticastReceiver.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/BlankenbekerMulticastReceiver.java index 9ad31b8bfc414d5bf7e862e08461dfe46e5c69c8..712001aa2fbfa50eefe6abe4674a2300dc0062ef 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/BlankenbekerMulticastReceiver.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/BlankenbekerMulticastReceiver.java @@ -24,7 +24,7 @@ public class BlankenbekerMulticastReceiver { /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; /** run the program * @param args command-line arguments, string parameters (unused) */ diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/BlankenbekerMulticastSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/BlankenbekerMulticastSender.java index 9b2ad6e5bd56d925753b298efc510cd366271713..304d603414cccbccd1b01e06d56de814b50c87f4 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/BlankenbekerMulticastSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/BlankenbekerMulticastSender.java @@ -24,7 +24,7 @@ public class BlankenbekerMulticastSender { /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; /** run the program * @param args command-line arguments, string parameters (unused) */ diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/ConardMulticastReceiver.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/ConardMulticastReceiver.java index d2be90d6c439879579a0fd74c773fc63f7535be3..5bcae090dd97e83a17c0bcd82194de23fd91d1b2 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/ConardMulticastReceiver.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/ConardMulticastReceiver.java @@ -20,7 +20,7 @@ public class ConardMulticastReceiver /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; /** * Program invocation, execution starts here diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/ConardMulticastSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/ConardMulticastSender.java index 2e81bb6d70b456109ccf93111c670950860d5fa5..aa0e0e604bcc486605ad45c58740a49b05d9f7cf 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/ConardMulticastSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/ConardMulticastSender.java @@ -20,7 +20,7 @@ public class ConardMulticastSender { /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; /** * Program invocation, execution starts here diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/HanleyMulticastHWreceiver.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/HanleyMulticastHWreceiver.java index ad417acfd360b933532a3870ee9c5e3af001c22d..ee217bc699a0391a81ed90b72743eb672a50a81a 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/HanleyMulticastHWreceiver.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/HanleyMulticastHWreceiver.java @@ -1,65 +1,70 @@ package MV3500Cohort2018JanuaryMarch.homework2; -/** - * This assignment uses the code from MV3500 example "multicastExample1" - * modifications were made to way the packet is read to facilitate the double - * instead of the float. - * - * @author Brian - */ -import java.io.*; -import java.net.*; - - -public class HanleyMulticastHWreceiver { - public static final String MULTICAST_ADDRESS = "239.1.2.15"; - public static final int DESTINATION_PORT = 1717; - /** How many routers can be crossed */ - public static final int TTL = 10; - - public static void main(String[] args) - { - try - { - - // 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 - // netbeans must be restarted after these settings. - // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache - System.setProperty("java.net.preferIPv4Stack", "true"); - - - MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); - multicastSocket.setTimeToLive(TTL); - InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); - System.out.println(multicastAddress); - // Join group useful on receiving side - multicastSocket.joinGroup(multicastAddress); - // You can join multiple groups here - - int count = 0; - - while(true) - { - byte[] packetArray = new byte[1500]; - DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); - - multicastSocket.receive(packet); - count++; - - ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); - DataInputStream dis = new DataInputStream(bais); - double firstNumber = dis.readDouble(); - double secondNumber = dis.readDouble(); - - System.out.println("Number received: " + count + " X Pos: " + firstNumber + " Y Pos: " + secondNumber); - } - } - catch(Exception e) - { - System.out.println(e); - } - } - -} +/** + * This assignment uses the code from MV3500 example "multicastExample1" + * modifications were made to way the packet is read to facilitate the double + * instead of the float. + * + * @author Brian + */ +import java.io.*; +import java.net.*; + + +public class HanleyMulticastHWreceiver +{ + /** socket parameter of interest */ + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + static final int TTL = 10; + + /** run the program + * @param args command-line arguments, string parameters (unused) */ + public static void main(String[] args) + { + try + { + + // 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 + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + int count = 0; + + while(true) + { + byte[] packetArray = new byte[1500]; + DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); + + multicastSocket.receive(packet); + count++; + + ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); + DataInputStream dis = new DataInputStream(bais); + double firstNumber = dis.readDouble(); + double secondNumber = dis.readDouble(); + + System.out.println("Number received: " + count + " X Pos: " + firstNumber + " Y Pos: " + secondNumber); + } + } + catch(Exception e) + { + System.out.println(e); + } + } + +} diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/HanleyMulticastHWsender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/HanleyMulticastHWsender.java index fbd8b1b3bc3f11a9de90f03d18a83fe51b49ada5..96338d3ee5ab025f2d2102a153ab11a8f6089fcf 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/HanleyMulticastHWsender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/HanleyMulticastHWsender.java @@ -1,87 +1,91 @@ package MV3500Cohort2018JanuaryMarch.homework2; -/** - * This assignment uses the code from MV3500 example "multicastExample1" - * modifications were made to the packet creation and where the packet is - * assembled. - * - * @author Brian - */ - - -import java.io.*; -import java.net.*; - - -public class HanleyMulticastHWsender { - public static final String MULTICAST_ADDRESS = "239.1.2.15"; - public static final int DESTINATION_PORT = 1717; - /** How many routers can be crossed */ - public static final int TTL = 10; - private int velocity; - private float xPos; - private float yPos; - - - public static void main(String[] args) - { - int velocity = 2; - int dir = 45; - double xPos = 0; - double yPos = 2; - - - try - { - // 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 - // netbeans must be restarted after these settings. - // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache - System.setProperty("java.net.preferIPv4Stack", "true"); - - - MulticastSocket multicastSocket = new MulticastSocket(1718); - multicastSocket.setTimeToLive(TTL); - InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); - System.out.println(multicastAddress); - // Join group useful on receiving side - multicastSocket.joinGroup(multicastAddress); - // You can join multiple groups here - - - // How fast does this go? Does UDP try to slow it down, or does - // this cause network problems? (hint: yes for an unlimited send - // rate, unlike TCP). How do you know on the receiving side - // that you haven't received a duplicate UDP packet, out of - // order packet, or dropped packet? - - for(int idx = 0; idx < 100; idx++) - { - - xPos = xPos + (Math.cos(Math.toRadians(dir))*velocity); //computes the horixontal displacement for each movement based on velocity - this is a fixed velocity and time increment - yPos = yPos + (Math.sin(Math.toRadians(dir))*velocity); //computes the vertical displacement for each movement based on velocity - this is a fixed velocity and time increment - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - dos.writeDouble(xPos); - dos.writeDouble(yPos); - - - byte[] buffer = baos.toByteArray(); - - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); - - multicastSocket.send(packet); - baos.reset(); - Thread.sleep(1000); // Send 100, one per second - System.out.println("Sent multicast packet " + idx + " of 100"); - } - } - catch(Exception e) - { - System.out.println(e); - } - } - -} +/** + * This assignment uses the code from MV3500 example "multicastExample1" + * modifications were made to the packet creation and where the packet is + * assembled. + * + * @author Brian + */ + + +import java.io.*; +import java.net.*; + + +public class HanleyMulticastHWsender +{ + /** socket parameter of interest */ + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + static final int TTL = 10; + private int velocity; + private float xPos; + private float yPos; + + /** run the program + * @param args command-line arguments, string parameters (unused) */ + public static void main(String[] args) + { + int velocity = 2; + int dir = 45; + double xPos = 0; + double yPos = 2; + + + try + { + // 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 + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(1718); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + + // How fast does this go? Does UDP try to slow it down, or does + // this cause network problems? (hint: yes for an unlimited send + // rate, unlike TCP). How do you know on the receiving side + // that you haven't received a duplicate UDP packet, out of + // order packet, or dropped packet? + + for(int idx = 0; idx < 100; idx++) + { + + xPos = xPos + (Math.cos(Math.toRadians(dir))*velocity); //computes the horixontal displacement for each movement based on velocity - this is a fixed velocity and time increment + yPos = yPos + (Math.sin(Math.toRadians(dir))*velocity); //computes the vertical displacement for each movement based on velocity - this is a fixed velocity and time increment + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + dos.writeDouble(xPos); + dos.writeDouble(yPos); + + + byte[] buffer = baos.toByteArray(); + + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); + + multicastSocket.send(packet); + baos.reset(); + Thread.sleep(1000); // Send 100, one per second + System.out.println("Sent multicast packet " + idx + " of 100"); + } + } + catch(Exception e) + { + System.out.println(e); + } + } + +} diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastReceiver.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastReceiver.java index 831bb617721d791133d4c8efea06be038fae96f2..427e6912c795d019da3c25ccbc8f79a6b40eb4b6 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastReceiver.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastReceiver.java @@ -16,7 +16,11 @@ public class LandasMulticastReceiver { final static String INET_ADDR = "239.1.2.15"; final static int PORT = 1717; - public static void main(String[] args) throws UnknownHostException { + /** run the program + * @param args command-line arguments, string parameters (unused) + * @throws java.net.UnknownHostException user cancels program */ + public static void main(String[] args) throws UnknownHostException + { // address that we are connecting to InetAddress address = InetAddress.getByName(INET_ADDR); diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastReceiver2.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastReceiver2.java index 96c2c15178fdeb980ca311a8b79c620e859b5a12..25fcf933e7c1d4c3e669f2a4968f2b405db4ca58 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastReceiver2.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastReceiver2.java @@ -16,6 +16,9 @@ public class LandasMulticastReceiver2 { final static String INET_ADDR = "239.1.2.15"; final static int PORT = 1717; + /** run the program + * @param args command-line arguments, string parameters (unused) + * @throws java.net.UnknownHostException user cancels program */ public static void main(String[] args) throws UnknownHostException { // address that we are connecting to InetAddress address = InetAddress.getByName(INET_ADDR); diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastSender.java index 8bbcd839df39b1a49bb7d801a31ed93d75762785..260c11ee5c89634cd345fb36b36605a9457c1648 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastSender.java @@ -16,6 +16,9 @@ public class LandasMulticastSender { final static String INET_ADDR = "239.1.2.15"; final static int PORT = 1717; + /** run the program + * @param args command-line arguments, string parameters (unused) + * @throws java.lang.InterruptedException user cancels execution */ public static void main(String[] args) throws UnknownHostException, InterruptedException { // address that we are connecting to InetAddress addr = InetAddress.getByName(INET_ADDR); diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastSender2.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastSender2.java index c28b2780bc32ce617ede330fffc9bfaf25ba1ff4..1f2855a388f848e5259a7221887c54a7b366f56a 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastSender2.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/LandasMulticastSender2.java @@ -16,6 +16,11 @@ public class LandasMulticastSender2 { final static String INET_ADDR = "239.1.2.15"; final static int PORT = 1717; + /** + * Program invocation, execution starts here + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution + */ public static void main(String[] args) throws UnknownHostException, InterruptedException { // address that we are connecting to InetAddress addr = InetAddress.getByName(INET_ADDR); diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/MaroonMulticastReceiver.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/MaroonMulticastReceiver.java index 2ffaee524ec5af5ff30830661253e35f804bbe05..a07e86c945e30085a09a33c29161fb5e05222b20 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/MaroonMulticastReceiver.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/MaroonMulticastReceiver.java @@ -15,13 +15,17 @@ import java.awt.event.ActionListener; * * @author mcgredo */ -public class MaroonMulticastReceiver { - +public class MaroonMulticastReceiver +{ + /** socket parameter of interest */ public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; + /** run the program + * @param args command-line arguments, string parameters (unused) */ public static void main(String[] args) { JFrame guiFrame = new JFrame(); diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/MaroonMulticastSenderExample.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/MaroonMulticastSenderExample.java index e263b5750c6caacb12d85fcf45bfb40c6ce1658e..ef9c7f5f534e63af3785faaf029a45868434ae9f 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/MaroonMulticastSenderExample.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/MaroonMulticastSenderExample.java @@ -11,13 +11,17 @@ import java.net.*; * * @author mcgredo */ -public class MaroonMulticastSenderExample { - +public class MaroonMulticastSenderExample +{ + /** socket parameter of interest */ public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; // Time to Live is decrement counter to limit scope + static final int TTL = 10; // Time to Live is decrement counter to limit scope + /** run the program + * @param args command-line arguments, string parameters (unused) */ public static void main(String[] args) { try diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SasalaMulticastReceiver.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SasalaMulticastReceiver.java index ff2e874ab5a1655b9ac057d436a6e11bbac027a7..6a58c395484894e194c734576b303957c8538274 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SasalaMulticastReceiver.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SasalaMulticastReceiver.java @@ -10,13 +10,17 @@ import java.net.*; * * @author mcgredo */ -public class SasalaMulticastReceiver { - +public class SasalaMulticastReceiver +{ + /** socket parameter of interest */ public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; + /** run the program + * @param args command-line arguments, string parameters (unused) */ public static void main(String[] args) { try diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SasalaMulticastSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SasalaMulticastSender.java index fdafb40edd73b59203f4c446e2f21454aa5fbca6..10d7ecc10e02ccccec34daa4c40bf17df27443dd 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SasalaMulticastSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SasalaMulticastSender.java @@ -14,11 +14,15 @@ import java.time.LocalDateTime; */ public class SasalaMulticastSender { + /** socket parameter of interest */ public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; + /** run the program + * @param args command-line arguments, string parameters (unused) */ public static void main(String[] args) { try diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SnellMulticastClient.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SnellMulticastClient.java index 83f965569b9974cd0761c46da779294dd8437610..a0ee80be1b3324fd05856d2661692394e8781803 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SnellMulticastClient.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SnellMulticastClient.java @@ -1,71 +1,76 @@ package MV3500Cohort2018JanuaryMarch.homework2; -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -//package HW2; - -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.net.DatagramPacket; -import java.net.InetAddress; -import java.net.MulticastSocket; - -/** - * - * @author Justin Snell - */ -public class SnellMulticastClient { - public static final String MULTICAST_ADDRESS = "239.1.2.15"; - public static final int DESTINATION_PORT = 1717; - /** How many routers can be crossed */ - public static final int TTL = 10; - - public static void main(String[] args) - { - try - { - - // 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 - // netbeans must be restarted after these settings. - // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache - System.setProperty("java.net.preferIPv4Stack", "true"); - - - MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); - multicastSocket.setTimeToLive(TTL); - InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); - System.out.println(multicastAddress); - // Join group useful on receiving side - multicastSocket.joinGroup(multicastAddress); - // You can join multiple groups here - - int count = 0; - - while(true) - { - byte[] packetArray = new byte[1500]; - DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); - - multicastSocket.receive(packet); - count++; - - ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); - DataInputStream dis = new DataInputStream(bais); - int firstNumber = dis.readInt(); - int secondNumber = dis.readInt(); - - System.out.println("Number received: " + count + " xpos:" + firstNumber + " ypos:" + secondNumber); - } - } - catch(Exception e) - { - System.out.println(e); - } - } - -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +//package HW2; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; + +/** + * + * @author Justin Snell + */ +public class SnellMulticastClient +{ + /** socket parameter of interest */ + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + static final int TTL = 10; + + /** run the program + * @param args command-line arguments, string parameters (unused) */ + public static void main(String[] args) + { + try + { + + // 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 + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + int count = 0; + + while(true) + { + byte[] packetArray = new byte[1500]; + DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); + + multicastSocket.receive(packet); + count++; + + ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); + DataInputStream dis = new DataInputStream(bais); + int firstNumber = dis.readInt(); + int secondNumber = dis.readInt(); + + System.out.println("Number received: " + count + " xpos:" + firstNumber + " ypos:" + secondNumber); + } + } + catch(Exception e) + { + System.out.println(e); + } + } + +} diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SnellMulticastServer.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SnellMulticastServer.java index 5b92d0f7024a0da863b7cded38433ac184f3dd00..1c5d161ab05395aa7a463aeb89a258ca573afadd 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SnellMulticastServer.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/SnellMulticastServer.java @@ -1,73 +1,78 @@ package MV3500Cohort2018JanuaryMarch.homework2; -//package HW2; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.net.DatagramPacket; -import java.net.InetAddress; -import java.net.MulticastSocket; - -public class SnellMulticastServer { - public static final String MULTICAST_ADDRESS = "239.1.2.15"; - public static final int DESTINATION_PORT = 1717; - /** How many routers can be crossed */ - public static final int TTL = 10; - - public static void main(String[] args) - { - try - { - // 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 - // netbeans must be restarted after these settings. - // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache - System.setProperty("java.net.preferIPv4Stack", "true"); - - - MulticastSocket multicastSocket = new MulticastSocket(1718); - multicastSocket.setTimeToLive(TTL); - InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); - System.out.println(multicastAddress); - // Join group useful on receiving side - multicastSocket.joinGroup(multicastAddress); - // You can join multiple groups here - - int xpos = 12; - int ypos = 15; - - // Put together a message with binary content. "ByteArrayOutputStream" - // is a java.io utility that lets us put together an array of binary - // data, which we put into the UDP packet. - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - dos.writeInt(xpos); - dos.writeInt(ypos); - byte[] buffer = baos.toByteArray(); - - // Put together a packet to send - // muticast group we are sending to--not a single host - - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); - - // How fast does this go? Does UDP try to slow it down, or does - // this cause network problems? (hint: yes for an unlimited send - // rate, unlike TCP). How do you know on the receiving side - // that you haven't received a duplicate UDP packet, out of - // order packet, or dropped packet? - - for(int idx = 0; idx < 100; idx++) - { - multicastSocket.send(packet); - Thread.sleep(1000); // Send 100, one per second - System.out.println("Sent multicast packet " + idx + " of 100"); - } - } - catch(Exception e) - { - System.out.println(e); - } - } -} +//package HW2; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; + +public class SnellMulticastServer +{ + /** socket parameter of interest */ + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + static final int TTL = 10; + + /** run the program + * @param args command-line arguments, string parameters (unused) */ + public static void main(String[] args) + { + try + { + // 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 + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(1718); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + int xpos = 12; + int ypos = 15; + + // Put together a message with binary content. "ByteArrayOutputStream" + // is a java.io utility that lets us put together an array of binary + // data, which we put into the UDP packet. + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + dos.writeInt(xpos); + dos.writeInt(ypos); + byte[] buffer = baos.toByteArray(); + + // Put together a packet to send + // muticast group we are sending to--not a single host + + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); + + // How fast does this go? Does UDP try to slow it down, or does + // this cause network problems? (hint: yes for an unlimited send + // rate, unlike TCP). How do you know on the receiving side + // that you haven't received a duplicate UDP packet, out of + // order packet, or dropped packet? + + for(int idx = 0; idx < 100; idx++) + { + multicastSocket.send(packet); + Thread.sleep(1000); // Send 100, one per second + System.out.println("Sent multicast packet " + idx + " of 100"); + } + } + catch(Exception e) + { + System.out.println(e); + } + } +} diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/TackettMultiCastReceiver.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/TackettMultiCastReceiver.java index 79ea1e5fbf4c4b8dc7f0572ad24a0d90849bb63b..8b5e59b607bd644912fa4bfbc5f3fb36f3c05e11 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/TackettMultiCastReceiver.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/TackettMultiCastReceiver.java @@ -1,65 +1,70 @@ package MV3500Cohort2018JanuaryMarch.homework2; -/** - * This assignment uses the code from MV3500 example "multicastExample1" - * modifications were made to way the packet is read to facilitate the double - * instead of the float. - * - * @author codyt - */ -import java.io.*; -import java.net.*; - - -public class TackettMultiCastReceiver { - public static final String MULTICAST_ADDRESS = "239.1.2.15"; - public static final int DESTINATION_PORT = 1717; - /** How many routers can be crossed */ - public static final int TTL = 10; - - public static void main(String[] args) - { - try - { - - // 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 - // netbeans must be restarted after these settings. - // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache - System.setProperty("java.net.preferIPv4Stack", "true"); - - - MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); - multicastSocket.setTimeToLive(TTL); - InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); - System.out.println(multicastAddress); - // Join group useful on receiving side - multicastSocket.joinGroup(multicastAddress); - // You can join multiple groups here - - int count = 0; - - while(true) - { - byte[] packetArray = new byte[1500]; - DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); - - multicastSocket.receive(packet); - count++; - - ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); - DataInputStream dis = new DataInputStream(bais); - double firstNumber = dis.readDouble(); - double secondNumber = dis.readDouble(); - - System.out.println("Number received: " + count + " X Pos: " + firstNumber + " Y Pos: " + secondNumber); - } - } - catch(Exception e) - { - System.out.println(e); - } - } - -} +/** + * This assignment uses the code from MV3500 example "multicastExample1" + * modifications were made to way the packet is read to facilitate the double + * instead of the float. + * + * @author codyt + */ +import java.io.*; +import java.net.*; + + +public class TackettMultiCastReceiver +{ + /** socket parameter of interest */ + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + static final int TTL = 10; + + /** run the program + * @param args command-line arguments, string parameters (unused) */ + public static void main(String[] args) + { + try + { + + // 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 + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + int count = 0; + + while(true) + { + byte[] packetArray = new byte[1500]; + DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); + + multicastSocket.receive(packet); + count++; + + ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); + DataInputStream dis = new DataInputStream(bais); + double firstNumber = dis.readDouble(); + double secondNumber = dis.readDouble(); + + System.out.println("Number received: " + count + " X Pos: " + firstNumber + " Y Pos: " + secondNumber); + } + } + catch(Exception e) + { + System.out.println(e); + } + } + +} diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/TackettMulticastSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/TackettMulticastSender.java index 59b5a2ce8b97623eef8c19243a413bab9dfc7090..d65093eb5bbe547acd657b0df34db8e34c509dcd 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/TackettMulticastSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/TackettMulticastSender.java @@ -13,11 +13,14 @@ import java.io.*; import java.net.*; -public class TackettMulticastSender { +public class TackettMulticastSender +{ + /** socket parameter of interest */ public static final String MULTICAST_ADDRESS = "172.20.144.145"; + /** socket parameter of interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; private int velocity; private float xPos; private float yPos; diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/YamashitaDeMouraMulticastReceiver.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/YamashitaDeMouraMulticastReceiver.java index 071fd2d9383c9dcf27dff2235550ef6a217ba9d7..2c5a025bd0b39456376e3cd780186886c06ba9ba 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/YamashitaDeMouraMulticastReceiver.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/YamashitaDeMouraMulticastReceiver.java @@ -1,79 +1,85 @@ package MV3500Cohort2018JanuaryMarch.homework2; - -import java.io.*; -import java.net.*; -import java.util.Random; - -/** - * MV3500 - * - * Multicast Receiver - * - * @author Douglas Yamashita de Moura - * @version 20180227 - * - */ -public class YamashitaDeMouraMulticastReceiver { - - public static final String MULTICAST_ADDRESS = "239.1.2.15"; - public static final int DESTINATION_PORT = 1717; - public static final int TTL = 10; - - public static void main(String[] args) - { - try - { - System.setProperty("java.net.preferIPv4Stack", "true"); - MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); - multicastSocket.setTimeToLive(TTL); - InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); - System.out.println(multicastAddress); - multicastSocket.joinGroup(multicastAddress); - int count = 0; - - int randomReceiver = new Random().nextInt(100); - System.out.println("=== MULTICAST RECEIVER " + randomReceiver + " ==="); - - while(true) - { - byte[] packetArray = new byte[1500]; - DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); - multicastSocket.receive(packet); - count++; - ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); - DataInputStream dis = new DataInputStream(bais); - char entity = dis.readChar(); - String name = ""; - int nameLength = 0; - switch(entity) { - case 'A': - nameLength = 4; - name = "A"; - break; - case 'B': - nameLength = 4; - name = "B"; - break; - } - - // Read name - for (int i = 0; i < nameLength; i++) { - name += dis.readChar(); - } - - // Read Position - float xPos = dis.readFloat(); - float yPos = dis.readFloat(); - float zPos = dis.readFloat(); - System.out.println("Entity '" + name + "' with position (" + xPos + - ", " + yPos + ", " + zPos +")."); - System.out.println("Number received: " + count); - } - } - catch(Exception e) - { - System.out.println(e); - } - } -} + +import java.io.*; +import java.net.*; +import java.util.Random; + +/** + * MV3500 + * + * Multicast Receiver + * + * @author Douglas Yamashita de Moura + * @version 20180227 + * + */ +public class YamashitaDeMouraMulticastReceiver { + + /** socket parameter of interest */ + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ + public static final int DESTINATION_PORT = 1717; + static final int TTL = 10; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) + { + try + { + System.setProperty("java.net.preferIPv4Stack", "true"); + MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + multicastSocket.joinGroup(multicastAddress); + int count = 0; + + int randomReceiver = new Random().nextInt(100); + System.out.println("=== MULTICAST RECEIVER " + randomReceiver + " ==="); + + while(true) + { + byte[] packetArray = new byte[1500]; + DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); + multicastSocket.receive(packet); + count++; + ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); + DataInputStream dis = new DataInputStream(bais); + char entity = dis.readChar(); + String name = ""; + int nameLength = 0; + switch(entity) { + case 'A': + nameLength = 4; + name = "A"; + break; + case 'B': + nameLength = 4; + name = "B"; + break; + } + + // Read name + for (int i = 0; i < nameLength; i++) { + name += dis.readChar(); + } + + // Read Position + float xPos = dis.readFloat(); + float yPos = dis.readFloat(); + float zPos = dis.readFloat(); + System.out.println("Entity '" + name + "' with position (" + xPos + + ", " + yPos + ", " + zPos +")."); + System.out.println("Number received: " + count); + } + } + catch(Exception e) + { + System.out.println(e); + } + } +} diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/YamashitaDeMouraMulticastSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/YamashitaDeMouraMulticastSender.java index f61601a21da2ac2649bd5bae43703881abfc1e1f..2d88a602638a664950faba1efbb0e1b7fe2a5387 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/YamashitaDeMouraMulticastSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework2/YamashitaDeMouraMulticastSender.java @@ -1,87 +1,91 @@ package MV3500Cohort2018JanuaryMarch.homework2; - -import java.io.*; -import java.net.*; -import java.util.Random; - -/** - * MV3500 - * - * Multicast Sender - * - * @author Douglas Yamashita de Moura - * @version 20180227 - * - */ -public class YamashitaDeMouraMulticastSender { - - public static final String MULTICAST_ADDRESS = "239.1.2.15"; - public static final int DESTINATION_PORT = 1717; - public static final int TTL = 10; - - - public static void main(String[] args) - { - YamashitaDeMouraMulticastEntity entityA = new YamashitaDeMouraMulticastEntity("Alpha", 0, 0, 0, 2); - YamashitaDeMouraMulticastEntity entityB = new YamashitaDeMouraMulticastEntity("Bravo", 0, 0, 0, 3); - - try - { - System.setProperty("java.net.preferIPv4Stack", "true"); - - MulticastSocket multicastSocket = new MulticastSocket(1718); - multicastSocket.setTimeToLive(TTL); - InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); - System.out.println(multicastAddress); - multicastSocket.joinGroup(multicastAddress); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - - Random randomProb = new Random(); - - System.out.println("=== MULTICAST SENDER ==="); - - for(int idx = 1; idx < 100; idx++) - { - int prob = randomProb.nextInt(5); - - if(prob < 2) { - dos.writeChars(entityA.getName()); - // Move only in x direction - float newPos = entityA.getX()+entityA.getVelocity(); - entityA.setX(newPos); - dos.writeFloat(entityA.getX()); - dos.writeFloat(entityA.getY()); - dos.writeFloat(entityA.getZ()); - System.out.println("Entity '" + entityA.getName() + - "' with position (" + entityA.getX() + ", " + - entityA.getY() + ", " + entityA.getZ() + ")"); - } else if (prob < 5) { - dos.writeChars(entityB.getName()); - dos.writeFloat(entityB.getX()); - // Move only in y direction - float newPos = entityB.getY()+entityB.getVelocity(); - entityB.setY(newPos); - dos.writeFloat(entityB.getY()); - dos.writeFloat(entityB.getZ()); - System.out.println("Entity '" + entityB.getName() + - "' with position (" + entityB.getX() + ", " + - entityB.getY() + ", " + entityB.getZ() + ")"); - } - - byte[] buffer = baos.toByteArray(); - - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); - multicastSocket.send(packet); - baos.reset(); - Thread.sleep(1000); // Send 100, one per second - System.out.println("Sent multicast packet " + idx + " of 100"); - } - } - catch(Exception e) - { - System.out.println(e); - } - } -} + +import java.io.*; +import java.net.*; +import java.util.Random; + +/** + * MV3500 + * + * Multicast Sender + * + * @author Douglas Yamashita de Moura + * @version 20180227 + * + */ +public class YamashitaDeMouraMulticastSender +{ + /** socket parameter of interest */ + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ + public static final int DESTINATION_PORT = 1717; + static final int TTL = 10; + + + /** Program invocation, execution starts here + * @param args command-line arguments */ + public static void main(String[] args) + { + YamashitaDeMouraMulticastEntity entityA = new YamashitaDeMouraMulticastEntity("Alpha", 0, 0, 0, 2); + YamashitaDeMouraMulticastEntity entityB = new YamashitaDeMouraMulticastEntity("Bravo", 0, 0, 0, 3); + + try + { + System.setProperty("java.net.preferIPv4Stack", "true"); + + MulticastSocket multicastSocket = new MulticastSocket(1718); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + multicastSocket.joinGroup(multicastAddress); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + + Random randomProb = new Random(); + + System.out.println("=== MULTICAST SENDER ==="); + + for(int idx = 1; idx < 100; idx++) + { + int prob = randomProb.nextInt(5); + + if(prob < 2) { + dos.writeChars(entityA.getName()); + // Move only in x direction + float newPos = entityA.getX()+entityA.getVelocity(); + entityA.setX(newPos); + dos.writeFloat(entityA.getX()); + dos.writeFloat(entityA.getY()); + dos.writeFloat(entityA.getZ()); + System.out.println("Entity '" + entityA.getName() + + "' with position (" + entityA.getX() + ", " + + entityA.getY() + ", " + entityA.getZ() + ")"); + } else if (prob < 5) { + dos.writeChars(entityB.getName()); + dos.writeFloat(entityB.getX()); + // Move only in y direction + float newPos = entityB.getY()+entityB.getVelocity(); + entityB.setY(newPos); + dos.writeFloat(entityB.getY()); + dos.writeFloat(entityB.getZ()); + System.out.println("Entity '" + entityB.getName() + + "' with position (" + entityB.getX() + ", " + + entityB.getY() + ", " + entityB.getZ() + ")"); + } + + byte[] buffer = baos.toByteArray(); + + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); + multicastSocket.send(packet); + baos.reset(); + Thread.sleep(1000); // Send 100, one per second + System.out.println("Sent multicast packet " + idx + " of 100"); + } + } + catch(Exception e) + { + System.out.println(e); + } + } +} diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Angel_OpenDisEspduSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Angel_OpenDisEspduSender.java index 674acbcea5fbc1afb5e2d12a775876fde97a0bf3..0389944666a6f46ebbc1805990d5730cdb3ad077 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Angel_OpenDisEspduSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Angel_OpenDisEspduSender.java @@ -17,7 +17,7 @@ import edu.nps.moves.disutil.DisTime; */ public class Angel_OpenDisEspduSender { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/BlankenbekerOpenDisEspduSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/BlankenbekerOpenDisEspduSender.java index cfab01793ab677ba867de7b7322a34b7d766bf53..824ed6224705ba1172a1cd28f7cc6a055ad11fd0 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/BlankenbekerOpenDisEspduSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/BlankenbekerOpenDisEspduSender.java @@ -18,7 +18,7 @@ import edu.nps.moves.disutil.DisTime; public class BlankenbekerOpenDisEspduSender { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/ConardSnellOpenDisEspduSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/ConardSnellOpenDisEspduSender.java index e5919470b2d09b6e54436817fa7b751dc436f2a5..da85db1aad685b67c4d3c6add3c1f38bdf2f65a0 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/ConardSnellOpenDisEspduSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/ConardSnellOpenDisEspduSender.java @@ -17,7 +17,7 @@ import edu.nps.moves.disutil.DisTime; */ public class ConardSnellOpenDisEspduSender { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/EspduReceiver.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/EspduReceiver.java index 718c23fc4be3b96a93c2469e1d215d7a3074a192..6454420a8f7f66db931703c9f43c0687ca8c518e 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/EspduReceiver.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/EspduReceiver.java @@ -20,6 +20,8 @@ public class EspduReceiver { */ public static final int MAX_PDU_SIZE = 8192; + /** Program invocation, execution starts here + * @param args command-line arguments */ public static void main(String args[]) { MulticastSocket socket; DatagramPacket packet; diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Hanley_OpenDisEspduSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Hanley_OpenDisEspduSender.java index 0857a42f7ba7283d360e006384cd2816376fcb2f..957249a3fbda4e51f7fde783accba19476622dd8 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Hanley_OpenDisEspduSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Hanley_OpenDisEspduSender.java @@ -17,7 +17,7 @@ import edu.nps.moves.disutil.DisTime; */ public class Hanley_OpenDisEspduSender { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Landas_OpenDisEspduSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Landas_OpenDisEspduSender.java index 5235b1563a73c7b53051e808f8d7b8ae6a190693..74f507eaa87b49c665f63281811ab8fdd771d7c3 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Landas_OpenDisEspduSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Landas_OpenDisEspduSender.java @@ -17,7 +17,7 @@ import edu.nps.moves.disutil.DisTime; */ public class Landas_OpenDisEspduSender { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/OpenDisEspduSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/OpenDisEspduSender.java index 1f808475bc2985981ba3c41bcffc4e866e12d071..de4f3198812cdeb75c811deb006d4f4f9a64d783 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/OpenDisEspduSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/OpenDisEspduSender.java @@ -17,7 +17,7 @@ import edu.nps.moves.disutil.DisTime; */ public class OpenDisEspduSender { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/OpenDisPduSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/OpenDisPduSender.java index a592ad4d1e3e05ca14b3ec87e4ea35cf05f2bbec..94572a82958458a6fbe769f96b13cf34d1285207 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/OpenDisPduSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/OpenDisPduSender.java @@ -1,184 +1,190 @@ package MV3500Cohort2018JanuaryMarch.homework3; -// package edu.nps.moves.examples; // copy example from OpenDIS distribution, modify to serve as template - -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis.*; // OpenDIS version 4 -import edu.nps.moves.disenum.*; - -/** - * This is an example that sends many/most types of PDUs. Useful for testing standards - * compliance or getting a full set of PDUs. It also writes the generated PDUs to - * an XML file. - * - * @author DMcG - * @version $Id:$ - */ -public class OpenDisPduSender { - - public static final int PORT = 3000; - public static final String MULTICAST_ADDRESS = "239.1.2.3"; - private int port; - InetAddress multicastAddress; - - public OpenDisPduSender(int port, String multicast) - { - try { - this.port = port; - multicastAddress = InetAddress.getByName(multicast); - if (!multicastAddress.isMulticastAddress()) { - System.out.println("Not a multicast address: " + multicast); - } - } - catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); - } - } - - public void run() { - try { - List<Pdu> generatedPdus = new ArrayList<>(); - - // Loop through all the enumerated PDU types, create a PDU for each type, - // and add that PDU to a list. - for (PduType pdu : PduType.values()) { - Pdu aPdu = null; - - switch (pdu) { - case ENTITY_STATE: - // TODO continue to add unit tests - EntityStatePdu entityStatePdu = new EntityStatePdu(); - Marking espduMarking = new Marking(); - espduMarking.setCharactersString("Testing 123"); - // TODO libary should warn if > 11 characters - entityStatePdu.setMarking(espduMarking); - EntityID espduEntityID = new EntityID(); - espduEntityID.setSite(1); - espduEntityID.setApplication(2); - espduEntityID.setEntity(3); - entityStatePdu.setEntityID(espduEntityID); - // TODO consider adding utility methods to Open-DIS - aPdu = entityStatePdu; - break; - - case COMMENT: - aPdu = new CommentPdu(); - break; - - case FIRE: - aPdu = new FirePdu(); - break; - - case DETONATION: - aPdu = new DetonationPdu(); - break; - - case COLLISION: - aPdu = new CollisionPdu(); - break; - - case SERVICE_REQUEST: - aPdu = new ServiceRequestPdu(); - break; - - case RESUPPLY_OFFER: - aPdu = new ResupplyOfferPdu(); - break; - - case RESUPPLY_RECEIVED: - aPdu = new ResupplyReceivedPdu(); - break; - - case RESUPPLY_CANCEL: - aPdu = new ResupplyCancelPdu(); - break; - - case REPAIR_COMPLETE: - aPdu = new RepairCompletePdu(); - break; - - case REPAIR_RESPONSE: - aPdu = new RepairResponsePdu(); - break; - - case CREATE_ENTITY: - aPdu = new CreateEntityPdu(); - break; - - case REMOVE_ENTITY: - aPdu = new RemoveEntityPdu(); - break; - - case START_RESUME: - aPdu = new StartResumePdu(); - break; - - case STOP_FREEZE: - aPdu = new StopFreezePdu(); - break; - - case ACKNOWLEDGE: - aPdu = new AcknowledgePdu(); - break; - - case ACTION_REQUEST: - aPdu = new ActionRequestPdu(); - break; - - default: - System.out.print("PDU of type " + pdu + " not supported, created or sent "); - System.out.println(); - } - - if (aPdu != null) { - generatedPdus.add(aPdu); - } - } - - // Sort the created PDUs by class name - Collections.sort(generatedPdus, new edu.nps.moves.examples.ClassNameComparator()); - - // Send the PDUs we created - InetAddress localMulticastAddress = InetAddress.getByName(MULTICAST_ADDRESS); - MulticastSocket socket = new MulticastSocket(PORT); - socket.joinGroup(localMulticastAddress); - - for (int idx = 0; idx < generatedPdus.size(); idx++) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - byte[] buffer; - - Pdu aPdu = generatedPdus.get(idx); - aPdu.marshal(dos); - - buffer = baos.toByteArray(); - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, PORT); - socket.send(packet); - System.out.println("Sent PDU of type " + aPdu.getClass().getName()); - } - - // write the PDUs out to an XML file. - //PduContainer container = new PduContainer(); - //container.setPdus(generatedPdus); - //container.marshallToXml("examplePdus.xml"); - } - catch (IOException e) { - System.out.println(e); - } - } - - public static void main(String args[]) { - if (args.length == 2) { - OpenDisPduSender sender = new OpenDisPduSender(Integer.parseInt(args[0]), args[1]); - sender.run(); - } else { - System.out.println("Usage: OpenDisPduSender <port> <multicast group>"); - System.out.println("Default: OpenDisPduSender " + PORT + " " + MULTICAST_ADDRESS); - OpenDisPduSender sender = new OpenDisPduSender(PORT, MULTICAST_ADDRESS); - sender.run(); - } - } -} +// package edu.nps.moves.examples; // copy example from OpenDIS distribution, modify to serve as template + +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis.*; // OpenDIS version 4 +import edu.nps.moves.disenum.*; + +/** + * This is an example that sends many/most types of PDUs. Useful for testing standards + * compliance or getting a full set of PDUs. It also writes the generated PDUs to + * an XML file. + * + * @author DMcG + * @version $Id:$ + */ +public class OpenDisPduSender +{ + /** socket parameter of interest */ + public static final int PORT = 3000; + /** socket parameter of interest */ + public static final String MULTICAST_ADDRESS = "239.1.2.3"; + private int port; + InetAddress multicastAddress; + + public OpenDisPduSender(int port, String multicast) + { + try { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run() { + try { + List<Pdu> generatedPdus = new ArrayList<>(); + + // Loop through all the enumerated PDU types, create a PDU for each type, + // and add that PDU to a list. + for (PduType pdu : PduType.values()) { + Pdu aPdu = null; + + switch (pdu) { + case ENTITY_STATE: + // TODO continue to add unit tests + EntityStatePdu entityStatePdu = new EntityStatePdu(); + Marking espduMarking = new Marking(); + espduMarking.setCharactersString("Testing 123"); + // TODO libary should warn if > 11 characters + entityStatePdu.setMarking(espduMarking); + EntityID espduEntityID = new EntityID(); + espduEntityID.setSite(1); + espduEntityID.setApplication(2); + espduEntityID.setEntity(3); + entityStatePdu.setEntityID(espduEntityID); + // TODO consider adding utility methods to Open-DIS + aPdu = entityStatePdu; + break; + + case COMMENT: + aPdu = new CommentPdu(); + break; + + case FIRE: + aPdu = new FirePdu(); + break; + + case DETONATION: + aPdu = new DetonationPdu(); + break; + + case COLLISION: + aPdu = new CollisionPdu(); + break; + + case SERVICE_REQUEST: + aPdu = new ServiceRequestPdu(); + break; + + case RESUPPLY_OFFER: + aPdu = new ResupplyOfferPdu(); + break; + + case RESUPPLY_RECEIVED: + aPdu = new ResupplyReceivedPdu(); + break; + + case RESUPPLY_CANCEL: + aPdu = new ResupplyCancelPdu(); + break; + + case REPAIR_COMPLETE: + aPdu = new RepairCompletePdu(); + break; + + case REPAIR_RESPONSE: + aPdu = new RepairResponsePdu(); + break; + + case CREATE_ENTITY: + aPdu = new CreateEntityPdu(); + break; + + case REMOVE_ENTITY: + aPdu = new RemoveEntityPdu(); + break; + + case START_RESUME: + aPdu = new StartResumePdu(); + break; + + case STOP_FREEZE: + aPdu = new StopFreezePdu(); + break; + + case ACKNOWLEDGE: + aPdu = new AcknowledgePdu(); + break; + + case ACTION_REQUEST: + aPdu = new ActionRequestPdu(); + break; + + default: + System.out.print("PDU of type " + pdu + " not supported, created or sent "); + System.out.println(); + } + + if (aPdu != null) { + generatedPdus.add(aPdu); + } + } + + // Sort the created PDUs by class name + Collections.sort(generatedPdus, new edu.nps.moves.examples.ClassNameComparator()); + + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(PORT); + socket.joinGroup(localMulticastAddress); + + for (int idx = 0; idx < generatedPdus.size(); idx++) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdus.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, PORT); + socket.send(packet); + System.out.println("Sent PDU of type " + aPdu.getClass().getName()); + } + + // write the PDUs out to an XML file. + //PduContainer container = new PduContainer(); + //container.setPdus(generatedPdus); + //container.marshallToXml("examplePdus.xml"); + } + catch (IOException e) { + System.out.println(e); + } + } + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String args[]) { + if (args.length == 2) { + OpenDisPduSender sender = new OpenDisPduSender(Integer.parseInt(args[0]), args[1]); + sender.run(); + } else { + System.out.println("Usage: OpenDisPduSender <port> <multicast group>"); + System.out.println("Default: OpenDisPduSender " + PORT + " " + MULTICAST_ADDRESS); + OpenDisPduSender sender = new OpenDisPduSender(PORT, MULTICAST_ADDRESS); + sender.run(); + } + } +} diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Sasala_OpenDisEspduSender1.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Sasala_OpenDisEspduSender1.java index c583e0f4eec158f9dfb214354df8f65255104ec2..8e69a69a5ce4e4824e699b7692162305e4ef2bba 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Sasala_OpenDisEspduSender1.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Sasala_OpenDisEspduSender1.java @@ -16,7 +16,7 @@ import edu.nps.moves.disutil.DisTime; */ public class Sasala_OpenDisEspduSender1 { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Tackett_Assignment3_OpenDisEspduSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Tackett_Assignment3_OpenDisEspduSender.java index f3a80329ee7447cbadb904b0916adc61476101f4..f0cc8cdb2524021f0f8697c8b631dfa4910601ad 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Tackett_Assignment3_OpenDisEspduSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/Tackett_Assignment3_OpenDisEspduSender.java @@ -17,7 +17,7 @@ import edu.nps.moves.disutil.DisTime; */ public class Tackett_Assignment3_OpenDisEspduSender { - public static final int NUMBER_TO_SEND = 10; + static final int NUMBER_TO_SEND = 10; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/YamashitaDeMouraOpenDisEspduSender.java b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/YamashitaDeMouraOpenDisEspduSender.java index bc635f11ab087c913066097771d86ec4ed869721..f566339882114a783a33de71ed48340488e4becf 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/YamashitaDeMouraOpenDisEspduSender.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/homework3/YamashitaDeMouraOpenDisEspduSender.java @@ -20,7 +20,7 @@ import edu.nps.moves.disutil.DisTime; public class YamashitaDeMouraOpenDisEspduSender { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCP.java b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCP.java index 2581308e2dd230b8d3ba0478cb2418b779f8e19a..aba94c4e6a282bf928581cfee00488a0c7b34b34 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCP.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCP.java @@ -19,16 +19,19 @@ import java.io.DataOutputStream; */ public class AngelBlankEspduReceiverBtoTCP { + /** socket parameter of interest */ public static final String TCP_DESTINATION_IP = "172.20.144.187"; + /** socket parameter of interest */ public static final int DIS_DESTINATION_PORT = 2800; + /** socket parameter of interest */ public static final int TCP_DESTINATION_PORT = 2998; + /** socket parameter of interest */ public static final int MAX_PDU_SIZE = 8192; + /** socket parameter of interest */ public static final String GROUP = "239.1.2.3"; - /** - * Program invocation, execution starts here - * @param args command-line arguments - */ + /** Program invocation, execution starts here + * @param args command-line arguments */ public static void main(String args[]) { MulticastSocket socket; DatagramPacket packet; diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduSenderA.java b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduSenderA.java index 0e9f0d0772414bc8bb11e6e4c81a4fd3261faec5..1aa7b5bc2a10f8f215630eeadb701685e24b2c0b 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduSenderA.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduSenderA.java @@ -17,7 +17,7 @@ import edu.nps.moves.disutil.DisTime; */ public class AngelBlankEspduSenderA { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduSenderB.java b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduSenderB.java index 894e04cf75d86700d9c20254eeac4f5dffdd67cb..bc080d6601cdbf0068328b4fb621e300880e5f57 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduSenderB.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduSenderB.java @@ -17,7 +17,7 @@ import edu.nps.moves.disutil.DisTime; */ public class AngelBlankEspduSenderB { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { /** @see <a href="https://en.wikipedia.org/wiki/Unicast">https://en.wikipedia.org/wiki/Unicast</a> */ diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverASenderB.java b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverASenderB.java index f7e4756f1d5685458dacd6de33daefd2b94dd92e..8620080cff5fe37eb6ee83269f98d1d4c0eb505c 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverASenderB.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverASenderB.java @@ -19,7 +19,7 @@ import edu.nps.moves.disutil.DisTime; */ public class AngelBlankEspduTCPReceiverASenderB { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { /** @see <a href="https://en.wikipedia.org/wiki/Unicast">https://en.wikipedia.org/wiki/Unicast</a> */ @@ -31,7 +31,9 @@ public class AngelBlankEspduTCPReceiverASenderB }; /** default multicast group we send on */ public static final String DEFAULT_MULTICAST_GROUP="239.1.2.3"; + /** socket parameter of interest */ public static final int MAX_PDU_SIZE = 8192; + /** socket parameter of interest */ public static final int TCP_DESTINATION_PORT = 2999; /** Port we send on */ public static final int DIS_DESTINATION_PORT = 2800; diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverBSenderA.java b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverBSenderA.java index 07ae98a9fbac80a11ab6c54f9a11951a7760d6f8..e6b8b4857f7b5ebcf46217204c8da04c951e9449 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverBSenderA.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverBSenderA.java @@ -17,7 +17,7 @@ import edu.nps.moves.disutil.PduFactory; */ public class AngelBlankEspduTCPReceiverBSenderA { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { @@ -28,9 +28,11 @@ public class AngelBlankEspduTCPReceiverBSenderA /** @see <a href="https://en.wikipedia.org/wiki/Broadcasting_(networking)">https://en.wikipedia.org/wiki/Broadcasting_(networking)</a> */ BROADCAST }; + /** socket parameter of interest */ public static final int MAX_PDU_SIZE = 8192; /** default multicast group we send on */ public static final String DEFAULT_MULTICAST_GROUP="239.1.2.4"; + /** socket parameter of interest */ public static final int TCP_DESTINATION_PORT = 2998; /** Port we send on */ public static final int DIS_DESTINATION_PORT = 3000; diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/Hanley/HanleyOpenDisEspduSenderFP.java b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/Hanley/HanleyOpenDisEspduSenderFP.java index 688199cd26c8a5a63524909d93e2a85ff3f9e705..7853c9271412149aea2fcc1b981d1492675e532e 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/Hanley/HanleyOpenDisEspduSenderFP.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/Hanley/HanleyOpenDisEspduSenderFP.java @@ -26,7 +26,7 @@ import edu.nps.moves.disutil.DisTime; */ public class HanleyOpenDisEspduSenderFP { - //public static final int NUMBER_TO_SEND = 5000; + //static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { diff --git a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/SasalaMaroon/CSVreaderOpenDisEspduSenderFP.java b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/SasalaMaroon/CSVreaderOpenDisEspduSenderFP.java index 2ee59198cd39b01f18a4681efffd3920a2d2e221..64264ad0fd03c278889ba7e43d9493cac40ea211 100644 --- a/assignments/src/MV3500Cohort2018JanuaryMarch/projects/SasalaMaroon/CSVreaderOpenDisEspduSenderFP.java +++ b/assignments/src/MV3500Cohort2018JanuaryMarch/projects/SasalaMaroon/CSVreaderOpenDisEspduSenderFP.java @@ -32,9 +32,12 @@ import edu.nps.moves.disutil.DisTime; */ public class CSVreaderOpenDisEspduSenderFP { - //public static final int NUMBER_TO_SEND = 5000; + //static final int NUMBER_TO_SEND = 5000; + /** socket parameter of interest */ public static final int SENDING_PORT = 1414; + /** socket parameter of interest */ public static final int RECEIVING_PORT = 1415; + /** socket parameter of interest */ public static final String DESTINATION_HOST = "localhost"; /** Type of network connection */ diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Ayres_Client.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Ayres_Client.java index 4c08c937ba2fec1fb4c06545647600defec77bfa..3572ad23c457d67d6c1f01f40ec87a5dc28acbbc 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Ayres_Client.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Ayres_Client.java @@ -19,6 +19,7 @@ import java.net.Socket; */ public class Ayres_Client { + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1 /** diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/CainTcpClient.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/CainTcpClient.java index 8b18631fcd57e670e8e798f635687ced70d21744..075d9988bc5c6eef041fe4f8b237b93a9032c0b0 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/CainTcpClient.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/CainTcpClient.java @@ -7,8 +7,9 @@ import java.net.*; /** * credit to author mcgredo */ -public class CainTcpClient { - +public class CainTcpClient +{ + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1 /* @@ -18,6 +19,8 @@ public class CainTcpClient { * show up on both the client and server output so the conversation between * both makes sense and don't have to click back and forth to understand. */ + /** Program invocation, execution starts here + * @param args command-line arguments */ public static void main(String[] args) { try { while (true) { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/CainTcpServer.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/CainTcpServer.java index b73b55794b8bd56b53f4b10b7a59bc71ee938981..90f979f53e9c13a38457cc8e8c3bc955e1d7954a 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/CainTcpServer.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/CainTcpServer.java @@ -19,6 +19,10 @@ public class CainTcpServer * show up on both the client and server output so the conversation between * both makes sense and don't have to click back and forth to understand. */ + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { try diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/JacksonTcpClient.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/JacksonTcpClient.java index 81cd8c3715b685e93b130c01cc95de85ba7cd63e..0bb1cec615e5fcd2e6fc34dc6c2765614554bdf4 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/JacksonTcpClient.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/JacksonTcpClient.java @@ -13,12 +13,15 @@ import java.net.*; * * @author mcgredo */ -public class JacksonTcpClient { - +public class JacksonTcpClient +{ + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1 - - public static void main(String[] args) { + /** Program invocation, execution starts here + * @param args command-line arguments */ + public static void main(String[] args) + { int i = 1; try { while (true) { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/JacksonTcpServer.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/JacksonTcpServer.java index 004ebb63de5d11da9810f0f38ad14c996e599f66..043a9ebf8332ae7b35dd9565929ff4276265e877 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/JacksonTcpServer.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/JacksonTcpServer.java @@ -23,6 +23,8 @@ import java.net.*; */ public class JacksonTcpServer { + /** Program invocation, execution starts here + * @param args command-line arguments */ @SuppressWarnings("ConvertToTryWithResources") public static void main(String[] args) { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Client.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Client.java index 907b346e174bc0c8d410401c35aebaf95ab218ad..2e0692f9f0863a3a295eb94eaf5f0faadfa0431d 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Client.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Client.java @@ -18,10 +18,15 @@ import java.util.Scanner; * @author DonMcGregor * @author garrettloeffelman */ -public class LoeffelmanAssignment2Client { - +public class LoeffelmanAssignment2Client +{ + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1 + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { try { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Server.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Server.java index 303060e1e005c4e5ebb8dadf8ff4e270dedc506b..5711cf02c7886edb6560548a2e20ae7681fdb153 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Server.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Server.java @@ -22,6 +22,10 @@ import java.util.Scanner; */ public class LoeffelmanAssignment2Server { + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ @SuppressWarnings("ConvertToTryWithResources") public static void main(String[] args) { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Severson/SeversonAssignment2_Client.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Severson/SeversonAssignment2_Client.java index 4c7801d4fc21b43095e58f2e28ca960797e15318..e7fdb0bc7238dfc7464800c2015e855e49326402 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Severson/SeversonAssignment2_Client.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Severson/SeversonAssignment2_Client.java @@ -22,6 +22,7 @@ import javax.swing.JOptionPane; */ public class SeversonAssignment2_Client { + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; /** diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Thomerson/ThomersonAssignment2Client.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Thomerson/ThomersonAssignment2Client.java index d247794e283323e18bc9d7db8f7dfc9b9865907d..3fc7ecc52005020ae05d5de886d47221a3bac791 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Thomerson/ThomersonAssignment2Client.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Thomerson/ThomersonAssignment2Client.java @@ -23,10 +23,15 @@ import java.util.Scanner; * * @author courtneythomerson */ -public class ThomersonAssignment2Client { - +public class ThomersonAssignment2Client +{ + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1 + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { try { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Thomerson/ThomersonAssignment2Server.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Thomerson/ThomersonAssignment2Server.java index bd72a95d7a8f32e628b3f2b3d72c023b67068e04..c2a4992082b49dd9aa95d47340385fee2b84244c 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Thomerson/ThomersonAssignment2Server.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Thomerson/ThomersonAssignment2Server.java @@ -32,6 +32,10 @@ import java.net.Socket; public class ThomersonAssignment2Server { + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { try { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastReceiver.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastReceiver.java index 7bb7b29568b36942a7364b561cb3f45a577e4207..f3e1125f19eef61a10f9ae48d0709e42f8b9963f 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastReceiver.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastReceiver.java @@ -1,89 +1,92 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package MV3500Cohort2018JulySeptember.homework3.AyresDemchkoHomework3; - -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.InetAddress; -import java.net.MulticastSocket; -import java.net.UnknownHostException; -/** - * - * @author kjayr - */ -public class AyresDemchkoMulticastReceiver { -public static final String MULTICAST_ADDRESS = "239.1.2.15"; - public static final int DESTINATION_PORT = 1717; - /** How many routers can be crossed */ - public static final int TTL = 10; - - /** - * Program invocation, execution starts here - * @param args command-line arguments - */ - public static void main(String[] args) - { - try - { - - // 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 - // netbeans must be restarted after these settings. - // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache - System.setProperty("java.net.preferIPv4Stack", "true"); - - - MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); - multicastSocket.setTimeToLive(TTL); - InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); - System.out.println(multicastAddress); - // Join group useful on receiving side - multicastSocket.joinGroup(multicastAddress); - // You can join multiple groups here - - int count = 0; - int firstNumber = 11; - int secondNumber = 67; - int thirdNumber = 108; - int forkliftsAvail = 100; - int forkliftsServ = 0; - - while(true) - { - byte[] packetArray = new byte[1500]; - DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); - - multicastSocket.receive(packet); - count++; - firstNumber+=1.5; - secondNumber+=3.5; - thirdNumber+=5.0; - if(count > 1){ - forkliftsAvail-=1; - forkliftsServ+=1; - } - ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); - DataInputStream dis = new DataInputStream(bais); - //float firstNumber = dis.readInt(); - //float secondNumber = dis.readInt(); - //float thirdNumber = dis.readInt(); - - System.out.println("Marine Corps Logistics Base Albany: Wilson Warehouse"); - System.out.println("Order received: " + count + " NSN ID: " + firstNumber + " Xrow: " + secondNumber + " Yshelf: "+ thirdNumber + - " Forklifts Availble: " + forkliftsAvail + " Forklifts in Service: " +forkliftsServ); - System.out.println("______________________________________________________"); - } - } - catch(Exception e) - { - System.out.println(e); - } - } -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package MV3500Cohort2018JulySeptember.homework3.AyresDemchkoHomework3; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.MulticastSocket; +import java.net.UnknownHostException; +/** + * + * @author kjayr + */ +public class AyresDemchkoMulticastReceiver +{ + /** socket parameter of interest */ + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + static final int TTL = 10; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) + { + try + { + + // 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 + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + int count = 0; + int firstNumber = 11; + int secondNumber = 67; + int thirdNumber = 108; + int forkliftsAvail = 100; + int forkliftsServ = 0; + + while(true) + { + byte[] packetArray = new byte[1500]; + DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); + + multicastSocket.receive(packet); + count++; + firstNumber+=1.5; + secondNumber+=3.5; + thirdNumber+=5.0; + if(count > 1){ + forkliftsAvail-=1; + forkliftsServ+=1; + } + ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); + DataInputStream dis = new DataInputStream(bais); + //float firstNumber = dis.readInt(); + //float secondNumber = dis.readInt(); + //float thirdNumber = dis.readInt(); + + System.out.println("Marine Corps Logistics Base Albany: Wilson Warehouse"); + System.out.println("Order received: " + count + " NSN ID: " + firstNumber + " Xrow: " + secondNumber + " Yshelf: "+ thirdNumber + + " Forklifts Availble: " + forkliftsAvail + " Forklifts in Service: " +forkliftsServ); + System.out.println("______________________________________________________"); + } + } + catch(Exception e) + { + System.out.println(e); + } + } +} diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastSender.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastSender.java index 65a4ca1a6e0cc802416166550f14b09c03ea735e..f70237b53f67bfcd04e1d740a6300a364f43c4ec 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastSender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastSender.java @@ -1,72 +1,74 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package MV3500Cohort2018JulySeptember.homework3.AyresDemchkoHomework3; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.net.DatagramPacket; -import java.net.InetAddress; -import java.net.MulticastSocket; - -/** - * - * @author kjayr - */ -public class AyresDemchkoMulticastSender { - - public static final String MULTICAST_ADDRESS = "239.1.2.15"; - public static final int DESTINATION_PORT = 1717; - /** How many routers can be crossed */ - public static final int TTL = 10; - - /** - * Program invocation, execution starts here - * @param args command-line arguments - */ - public static void main(String[] args) - { - try - { - //int ID = 27; - //int xrow = 5; - //int yshelf = 7; - - System.setProperty("java.net.preferIPv4Stack", "true"); - - MulticastSocket multicastSocket = new MulticastSocket(1718); - multicastSocket.setTimeToLive(TTL); - InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); - System.out.println(multicastAddress); - // Join group useful on receiving side - multicastSocket.joinGroup(multicastAddress); - // You can join multiple groups here - - // Put together a message with binary content. "ByteArrayOutputStream" - // is a java.io utility that lets us put together an array of binary - // data, which we put into the UDP packet. - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - //dos.writeInt(ID); - //dos.writeInt(xrow); - //dos.writeInt(yshelf); - byte[] buffer = baos.toByteArray(); - - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); - - for(int idx = 0; idx < 100; idx++) - { - multicastSocket.send(packet); - Thread.sleep(1000); // Send 100, one per second - System.out.println("Sent multicast packet " + idx + " of 100"); - } - } - catch(Exception e) - { - System.out.println(e); - } - } -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package MV3500Cohort2018JulySeptember.homework3.AyresDemchkoHomework3; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; + +/** + * + * @author kjayr + */ +public class AyresDemchkoMulticastSender +{ + /** socket parameter of interest */ + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + static final int TTL = 10; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) + { + try + { + //int ID = 27; + //int xrow = 5; + //int yshelf = 7; + + System.setProperty("java.net.preferIPv4Stack", "true"); + + MulticastSocket multicastSocket = new MulticastSocket(1718); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + // Put together a message with binary content. "ByteArrayOutputStream" + // is a java.io utility that lets us put together an array of binary + // data, which we put into the UDP packet. + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + //dos.writeInt(ID); + //dos.writeInt(xrow); + //dos.writeInt(yshelf); + byte[] buffer = baos.toByteArray(); + + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); + + for(int idx = 0; idx < 100; idx++) + { + multicastSocket.send(packet); + Thread.sleep(1000); // Send 100, one per second + System.out.println("Sent multicast packet " + idx + " of 100"); + } + } + catch(Exception e) + { + System.out.println(e); + } + } +} diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Cain_Thomerson_Homework3/CainThomersonHw3Receiver.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Cain_Thomerson_Homework3/CainThomersonHw3Receiver.java index 1d6625175de65938f213b32df109ff300425559f..b6bf8e2344d64124877ee78e4cfe76447f528edc 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Cain_Thomerson_Homework3/CainThomersonHw3Receiver.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Cain_Thomerson_Homework3/CainThomersonHw3Receiver.java @@ -22,7 +22,7 @@ public class CainThomersonHw3Receiver /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; /** * Program invocation, execution starts here diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Cain_Thomerson_Homework3/CainThomersonHw3Sender.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Cain_Thomerson_Homework3/CainThomersonHw3Sender.java index 3055d1e598465be74e92acf02770712bcc0b875f..6209daeaa10f892833112f23b3564adfaca8d0b9 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Cain_Thomerson_Homework3/CainThomersonHw3Sender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Cain_Thomerson_Homework3/CainThomersonHw3Sender.java @@ -22,7 +22,7 @@ public class CainThomersonHw3Sender /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; /** * Program invocation, execution starts here diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Receiver.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Receiver.java index 1c4b4df7c2b016dc254d2516ffe39e2c9f8fe520..659d497d34fafcee160964da3ec6a4c7e52a33d1 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Receiver.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Receiver.java @@ -23,7 +23,7 @@ public class FurrFriscoHw3Receiver { /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; /** run the program * @param args command-line arguments, string parameters (unused) */ diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Sender.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Sender.java index 9bb743cf1477566ae7da1d949aec1edb3c47cd2c..7ccc4469e0e59af744f5b4c2554d89038c4deb52 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Sender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Sender.java @@ -22,7 +22,7 @@ public class FurrFriscoHw3Sender { /** * How many routers can be crossed */ - public static final int TTL = 10; + static final int TTL = 10; /** run the program * @param args command-line arguments, string parameters (unused) */ diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Jackson_UdpReceiver.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Jackson_UdpReceiver.java index 0396c08fc64711a74d20c2ddb8909a4bb838eff0..c968d290143f52c32a34b8d6090deea844ea2d42 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Jackson_UdpReceiver.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Jackson_UdpReceiver.java @@ -11,8 +11,11 @@ import java.net.*; */ public class Jackson_UdpReceiver { + /** socket parameter of interest */ public static final int SENDING_PORT = 1414; + /** socket parameter of interest */ public static final int RECEIVING_PORT = 1415; + /** socket parameter of interest */ public static final String DESINATION_HOST = "localhost"; /** diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Jackson_UdpSender.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Jackson_UdpSender.java index be60576ad0c6f0620bc961e653ee92eb7bc6e929..294a0fbe488e09820c239ca85101054e921fe087 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Jackson_UdpSender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Jackson_UdpSender.java @@ -13,13 +13,19 @@ import java.net.*; */ public class Jackson_UdpSender { - + /** socket parameter of interest */ public static final int SENDING_PORT = 1414; + /** socket parameter of interest */ public static final int RECEIVING_PORT = 1415; + /** socket parameter of interest */ public static final String DESTINATION_HOST = "localhost"; @SuppressWarnings("SleepWhileInLoop") + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { //int idx = 0; diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonMulticastImageHw3Receiver.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonMulticastImageHw3Receiver.java index 2c6b75d0c1e9dbf4f926068475c578558a674c6c..7116b2c677db18608d7b85c86c83f839d715323f 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonMulticastImageHw3Receiver.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonMulticastImageHw3Receiver.java @@ -22,15 +22,21 @@ import javax.swing.JLabel; * * @author garrettloeffelman */ -public class LoeffelmanSeversonMulticastImageHw3Receiver { - +public class LoeffelmanSeversonMulticastImageHw3Receiver +{ + /** socket parameter of interest */ public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ public static final int DESTINATION_PORT = 1717; /** * How many routers can be crossed */ - public static final int TTL = 20; + static final int TTL = 20; + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { try { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonMulticastImageHw3Sender.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonMulticastImageHw3Sender.java index 07714f7f6ce86fc46a6561fc9ff194792fbdaa78..9e61c068bb169c124b1823d0a79693c60f14f85f 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonMulticastImageHw3Sender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonMulticastImageHw3Sender.java @@ -20,13 +20,19 @@ import javax.imageio.ImageIO; * * @author garrettloeffelman */ -public class LoeffelmanSeversonMulticastImageHw3Sender { - +public class LoeffelmanSeversonMulticastImageHw3Sender +{ + /** socket parameter of interest */ public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ - public static final int TTL = 20; + static final int TTL = 20; + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { try diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonUDPImageHW3Receiver.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonUDPImageHW3Receiver.java index 7da665ca6b3fb0e0c54ad3ccb8434eff6a041856..89ed03b7d47fda406a39bcaa26720e31680fd194 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonUDPImageHW3Receiver.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonUDPImageHW3Receiver.java @@ -21,10 +21,13 @@ import javax.swing.JLabel; * * @author garrettloeffelman */ -public class LoeffelmanSeversonUDPImageHW3Receiver { - +public class LoeffelmanSeversonUDPImageHW3Receiver +{ + /** socket parameter of interest */ public static final int SENDING_PORT = 1414; + /** socket parameter of interest */ public static final int RECEIVING_PORT = 1415; + /** socket parameter of interest */ public static final String DESINATION_HOST = "localhost"; /** diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonUDPImageSender.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonUDPImageSender.java index 54bb672578cdbcae5a8e4fa37d5d1cf83f47704a..c8eaeba833a89cb625aa13335e3b7db841fa3189 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonUDPImageSender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Loeffelman_Severson_Homework3/LoeffelmanSeversonUDPImageSender.java @@ -19,12 +19,19 @@ import javax.imageio.ImageIO; * * @author garrettloeffelman */ -public class LoeffelmanSeversonUDPImageSender { - +public class LoeffelmanSeversonUDPImageSender +{ + /** socket parameter of interest */ public static final int SENDING_PORT = 1414; + /** socket parameter of interest */ public static final int RECEIVING_PORT = 1415; + /** socket parameter of interest */ public static final String DESTINATION_HOST = "localhost"; + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ @SuppressWarnings("SleepWhileInLoop") public static void main(String[] args) { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/AyresDemchko/AyresDemchkoReceiver.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/AyresDemchko/AyresDemchkoReceiver.java index 426e496605164fa08a7101571c2a1dd4fe1ec58c..65e32d4861ade473143b726de62af62c72821e87 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/AyresDemchko/AyresDemchkoReceiver.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/AyresDemchko/AyresDemchkoReceiver.java @@ -24,9 +24,12 @@ import java.util.ArrayList; */ public class AyresDemchkoReceiver { - public static final int MULTICAST_PORT = 3000; + /** socket parameter of interest */ + public static final int MULTICAST_PORT = 3000; + /** socket parameter of interest */ public static final String MULTICAST_GROUP = "239.1.2.15"; - public static final boolean USE_FAST_ESPDU = false; + /** socket parameter of interest */ + static final boolean USE_FAST_ESPDU = false; /** * Program invocation, execution starts here diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/AyresDemchko/AyresDemchkoSender.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/AyresDemchko/AyresDemchkoSender.java index 803053f03ccb92cb721f69f533220692db0146dd..75642117ad12d6e3f0e4e9a5b597372f787fcc71 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/AyresDemchko/AyresDemchkoSender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/AyresDemchko/AyresDemchkoSender.java @@ -42,9 +42,11 @@ import java.util.List; * * @author kjayr */ -public class AyresDemchkoSender { -/** Default multicast group address we send on. */ +public class AyresDemchkoSender +{ + /** Default multicast group address we send on. */ public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ public static final int DESTINATION_PORT = 1717; /** Default multicast port used, matches Wire-shark DIS capture default */ public static final int DEFAULT_MULTICAST_PORT = 3000; @@ -53,7 +55,9 @@ public class AyresDemchkoSender { private int port; InetAddress multicastAddress; - public AyresDemchkoSender (int port, String multicast) { + /** Object constructor */ + public AyresDemchkoSender (int port, String multicast) + { try { System.setProperty("java.net.preferIPv4Stack", "true"); diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/CainThomersonFinal/C_T_EspduSupplyerUnit.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/CainThomersonFinal/C_T_EspduSupplyerUnit.java index cea8f41ea71974b134274d54bcea542a7404bc68..a5e30ced221710099c6fded43a02a6288b47a015 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/CainThomersonFinal/C_T_EspduSupplyerUnit.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/CainThomersonFinal/C_T_EspduSupplyerUnit.java @@ -19,7 +19,7 @@ import java.io.IOException; */ public class C_T_EspduSupplyerUnit { - public static final int NUMBER_TO_SEND = 5000; + static final int NUMBER_TO_SEND = 5000; /** Type of network connection */ public enum NetworkMode { @@ -31,10 +31,11 @@ public class C_T_EspduSupplyerUnit { BROADCAST }; + /** socket parameter of interest */ public static final int MAX_PDU_SIZE = 8192; - + /** socket parameter of interest */ public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - + /** socket parameter of interest */ public static final int DEFAULT_MULTICAST_PORT = 3000; /** diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/FDCSendRecieve.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/FDCSendRecieve.java index 79ceb9f95f6afb56c061037560a5989db36af0ca..0acef815179f751b8f2e168b187b87f6435b72f4 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/FDCSendRecieve.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/FDCSendRecieve.java @@ -47,7 +47,7 @@ public class FDCSendRecieve { /** * This would be the sending Run method. Takes in several PDUs and for each one has a switch statement ready for it. - * @param pdupass + * @param pdupass passed pdu objects * @throws UnknownHostException unable to reach host address * @throws IOException input-output error */ diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/OBSSendRecieve1.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/OBSSendRecieve1.java index 9626b7feb798883e5d8842296018f77b43cdd19c..7d32391721eb625f49d5df12b6afc96056794dd5 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/OBSSendRecieve1.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/OBSSendRecieve1.java @@ -8,6 +8,7 @@ import java.io.IOException; import edu.nps.moves.disutil.PduFactory; import edu.nps.moves.disutil.DisTime; +/* Observer send, receive */ public class OBSSendRecieve1 { /** @@ -53,7 +54,7 @@ public class OBSSendRecieve1 { /** * This would be the sending Run method. Takes in several PDUs and for each one has a switch statement ready for it. - * @param pdupass + * @param pdupass passed pdu objects * @throws UnknownHostException unable to reach host address * @throws IOException input-output error */ diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/FDCSendRecieve.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/FDCSendRecieve.java index dd9c4f2a3920e617eb6277705cdd1739b29dbb6e..f726b83971ab8cd2a66206c1a24482cf5e84f598 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/FDCSendRecieve.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/FDCSendRecieve.java @@ -1,281 +1,288 @@ -package MV3500Cohort2018JulySeptember.projects.FriscoFurr.originals; - -import java.net.*; -import java.io.*; -import java.util.*; -import edu.nps.moves.dis.*; // OpenDIS version 4 -import java.io.IOException; -import edu.nps.moves.disutil.PduFactory; -import edu.nps.moves.disutil.DisTime; - -public class FDCSendRecieve { - - /** - * Default multicast group address we send on. - */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - - /** - * Default multicast port used, matches Wireshark DIS capture default - */ - public static final int DEFAULT_MULTICAST_PORT = 3000; - - private int port; - InetAddress multicastAddress; - - public static final int MULTICAST_PORT = 3000; - public static final String MULTICAST_GROUP = "239.1.2.3"; - public static final boolean USE_FAST_ESPDU = false; - public long[] sentBuffer = new long[100]; - public static List sentBufferList; - DisTime disTime = DisTime.getInstance(); - - public FDCSendRecieve(int port, String multicast) { - this.sentBufferList = new ArrayList<>(); - try { - this.port = port; - multicastAddress = InetAddress.getByName(multicast); - if (!multicastAddress.isMulticastAddress()) { - System.out.println("Not a multicast address: " + multicast); - } - } catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); - } - } - - public void run(Pdu... pdupass) throws UnknownHostException, IOException { - - List<Pdu> generatedPdus = new ArrayList<>(); - Pdu aPdu = null; - System.out.println("\nFDC Sender started..."); - // Send the PDUs we created - InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); - socket.joinGroup(localMulticastAddress); - - for (Pdu i : pdupass) { - Pdu pdu = i; - if (sentBufferList.contains(pdu.getTimestamp())) { - break; - } - - short currentPduType = pdu.getPduType(); - System.out.println("in sender, recived PDU type: " + currentPduType); - - switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* - { - - case 1: //ENTITY_STATE: - aPdu = pdu; - break; - - case 2: //FIRE - aPdu = pdu; - break; -// - case 15: //AcknowledgePdu - aPdu = pdu; - break; - - case 17: - aPdu = pdu; - break; - - case 14: - aPdu = pdu; - break; - - default: - System.out.print("PDU of type " + pdu + " not supported, created or sent "); - System.out.println(); - } - if (aPdu != null) { - generatedPdus.add(aPdu); - System.out.println("APDU container count " + generatedPdus.size()); - } - - } - for (int idx = 0; idx < generatedPdus.size(); idx++) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - byte[] buffer; - - aPdu = generatedPdus.get(idx); - aPdu.marshal(dos); - - buffer = baos.toByteArray(); - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); - socket.send(packet); - sentBufferList.add(aPdu.getTimestamp()); - System.out.println("Sent PDU of type " + aPdu.getClass().getName()+ "\n"); - } - } - - public static void main(String[] args) throws IOException, InterruptedException { - DisTime disTime = DisTime.getInstance(); - - FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender - - EntityStatePdu FDCespdu = new EntityStatePdu(); - Marking marking = new Marking(); - marking.setCharactersString("FDC"); - FDCespdu.setMarking(marking); - FDCespdu.setExerciseID((short) 1); - EntityID FDCID = FDCespdu.getEntityID(); - FDCID.setSite(1); // 0 is apparently not a valid site number, per the spec - FDCID.setApplication(1); - FDCID.setEntity(1); //change for each person I think??? - JMF - EntityType entityType = FDCespdu.getEntityType(); - // - //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 - // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 - // - entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 - entityType.setCountry(225); // USA TGT = 222 (Russia), OBS = 225 - entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 - entityType.setCategory((short) 3); // FDC TGT = 1, Tank OBS=40 OP - entityType.setSubcategory((short) 12); // M1068 TGT = 2, T72 tank NONE FOR OP - entityType.setSpec((short) 1); // M1068 w/ SICUP Tent NONE FOR TGT OR OP - Vector3Double location = new Vector3Double(); - location.setX(0.0); //TGT = 150 OBS = 75 - location.setY(0.0); //TGT = 150 OBS = 75 - location.setZ(10.0); //TGT = 20 OBS = 50 - FDCespdu.setEntityLocation(location); - int timestamp = disTime.getDisAbsoluteTimestamp(); - FDCespdu.setTimestamp(timestamp); - - sender.run(FDCespdu); //sends inital here I am and who I am - - //Set up other players to look for: - EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below - OBSEntityID.setEntity(2); - OBSEntityID.setApplication(1); - OBSEntityID.setSite(1); - - EntityID TGTEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below - TGTEntityID.setEntity(3); - TGTEntityID.setApplication(1); - TGTEntityID.setSite(1); - - /* BELOW IS THE RECIEVE CODE // - // // - // // - */ // - PduFactory factory; - MulticastSocket socket = null; - InetAddress address = null; - DatagramPacket packet; - short currentPduType = 0; //will use the curentPduType as the check for sending other packets. - - try { - System.out.println("FDC is alive and ready to recieve fire missions...\n\n"); - socket = new MulticastSocket(MULTICAST_PORT); - address = InetAddress.getByName(MULTICAST_GROUP); - socket.joinGroup(address); - - factory = new PduFactory(); - - while (true) // Loop infinitely, receiving datagrams - { - byte buffer[] = new byte[1500]; // typical MTU size - - packet = new DatagramPacket(buffer, buffer.length); // reset - - socket.receive(packet); - - String marking2 = new String(); - Pdu pdu = factory.createPdu(packet.getData()); - currentPduType = pdu.getPduType(); - if (currentPduType == 14) //stop/freeze PDU - { - System.out.println("recieved Stop/Freeze packet..."); - return; - } -// pdu.setExerciseID((short)5); - if (pdu != null) { - if (sentBufferList.contains(pdu.getTimestamp())) { - pdu = null; - } - if (pdu != null) { - - String currentPduTypeName = pdu.getClass().getName(); - - if (currentPduType == 1) { - EntityStatePdu pdu2 = (EntityStatePdu) pdu; - marking2 = pdu2.getMarking().getCharactersString(); - } - StringBuilder message = new StringBuilder(); - message.append("received DIS PDU: "); - message.append("pduType "); - if (currentPduType < 10) { - message.append(" "); - } - message.append(currentPduType).append(" ").append(currentPduTypeName); - message.append(" "); - message.append(marking2); - System.out.println(message.toString()); - //Reference for PDU Types: - // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm - // - - if (currentPduType == 1) //EntityState - { - EntityStatePdu entityPDU = (EntityStatePdu) pdu; - EntityType PduEntityType = entityPDU.getEntityType(); - if (PduEntityType.getCountry() == 225) { - Thread.sleep((long) 200); - timestamp = disTime.getDisAbsoluteTimestamp(); - FDCespdu.setTimestamp(timestamp); - System.out.println("Talking to the Observer, sending a radio check "); - sender.run(FDCespdu); - } - } - if (currentPduType == 16) //Action request - { - // Action response is sending a Null PDU, not sure why... - AcknowledgePdu ack = new AcknowledgePdu(); - ack.setExerciseID((short) 1); - ack.setRequestID((long) 1); - timestamp = disTime.getDisAbsoluteTimestamp(); - ack.setTimestamp(timestamp); - - FirePdu fire = new FirePdu(); - fire.setExerciseID((short) 1); - fire.setFireMissionIndex(1000); - fire.setRangeToTarget((float) Math.sqrt(Math.pow(150, 2) + Math.pow(150, 2))); //would pass in target info, but here we know location of tgt is (150,150) and FDC (0,0) - fire.setFiringEntityID(FDCID); - fire.setTargetEntityID(TGTEntityID); - timestamp = disTime.getDisAbsoluteTimestamp(); - fire.setTimestamp(timestamp); - sender.run(ack, fire); - } - - if (currentPduType == 22) //Comment PDU - { - AcknowledgePdu ack = new AcknowledgePdu(); - ack.setExerciseID((short) 1); - ack.setRequestID((long) 1); - timestamp = disTime.getDisAbsoluteTimestamp(); - ack.setTimestamp(timestamp); - - StopFreezePdu stop = new StopFreezePdu(); - stop.setExerciseID((short) 1); - stop.setRequestID((long) 1); - sender.run(ack, stop); - } - - } else { - System.out.println("received packet but pdu is null and originated from FDC. Still standing by..."); - } - } - } - } catch (IOException e) { - System.out.println("Problem with FDC.PduReceiver, see exception trace:"); - System.out.println(e); - } finally { - System.out.println("FDC.PduReceiver complete. - OUT!"); - } - - } - -} +package MV3500Cohort2018JulySeptember.projects.FriscoFurr.originals; + +import java.net.*; +import java.io.*; +import java.util.*; +import edu.nps.moves.dis.*; // OpenDIS version 4 +import java.io.IOException; +import edu.nps.moves.disutil.PduFactory; +import edu.nps.moves.disutil.DisTime; + +public class FDCSendRecieve { + + /** + * Default multicast group address we send on. + */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; + + /** + * Default multicast port used, matches Wireshark DIS capture default + */ + public static final int DEFAULT_MULTICAST_PORT = 3000; + + private int port; + InetAddress multicastAddress; + + /** socket parameter of interest */ + public static final int MULTICAST_PORT = 3000; + /** socket parameter of interest */ + public static final String MULTICAST_GROUP = "239.1.2.3"; + static final boolean USE_FAST_ESPDU = false; + private long[] sentBuffer = new long[100]; + private static List sentBufferList; + DisTime disTime = DisTime.getInstance(); + + public FDCSendRecieve(int port, String multicast) { + this.sentBufferList = new ArrayList<>(); + try { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) { + System.out.println("Not a multicast address: " + multicast); + } + } catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run(Pdu... pdupass) throws UnknownHostException, IOException { + + List<Pdu> generatedPdus = new ArrayList<>(); + Pdu aPdu = null; + System.out.println("\nFDC Sender started..."); + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (Pdu i : pdupass) { + Pdu pdu = i; + if (sentBufferList.contains(pdu.getTimestamp())) { + break; + } + + short currentPduType = pdu.getPduType(); + System.out.println("in sender, recived PDU type: " + currentPduType); + + switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* + { + + case 1: //ENTITY_STATE: + aPdu = pdu; + break; + + case 2: //FIRE + aPdu = pdu; + break; +// + case 15: //AcknowledgePdu + aPdu = pdu; + break; + + case 17: + aPdu = pdu; + break; + + case 14: + aPdu = pdu; + break; + + default: + System.out.print("PDU of type " + pdu + " not supported, created or sent "); + System.out.println(); + } + if (aPdu != null) { + generatedPdus.add(aPdu); + System.out.println("APDU container count " + generatedPdus.size()); + } + + } + for (int idx = 0; idx < generatedPdus.size(); idx++) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + aPdu = generatedPdus.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + sentBufferList.add(aPdu.getTimestamp()); + System.out.println("Sent PDU of type " + aPdu.getClass().getName()+ "\n"); + } + } + + /** + * Program invocation, execution starts here + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution + */ + public static void main(String[] args) throws IOException, InterruptedException { + DisTime disTime = DisTime.getInstance(); + + FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender + + EntityStatePdu FDCespdu = new EntityStatePdu(); + Marking marking = new Marking(); + marking.setCharactersString("FDC"); + FDCespdu.setMarking(marking); + FDCespdu.setExerciseID((short) 1); + EntityID FDCID = FDCespdu.getEntityID(); + FDCID.setSite(1); // 0 is apparently not a valid site number, per the spec + FDCID.setApplication(1); + FDCID.setEntity(1); //change for each person I think??? - JMF + EntityType entityType = FDCespdu.getEntityType(); + // + //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 + // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 + // + entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 + entityType.setCountry(225); // USA TGT = 222 (Russia), OBS = 225 + entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 + entityType.setCategory((short) 3); // FDC TGT = 1, Tank OBS=40 OP + entityType.setSubcategory((short) 12); // M1068 TGT = 2, T72 tank NONE FOR OP + entityType.setSpec((short) 1); // M1068 w/ SICUP Tent NONE FOR TGT OR OP + Vector3Double location = new Vector3Double(); + location.setX(0.0); //TGT = 150 OBS = 75 + location.setY(0.0); //TGT = 150 OBS = 75 + location.setZ(10.0); //TGT = 20 OBS = 50 + FDCespdu.setEntityLocation(location); + int timestamp = disTime.getDisAbsoluteTimestamp(); + FDCespdu.setTimestamp(timestamp); + + sender.run(FDCespdu); //sends inital here I am and who I am + + //Set up other players to look for: + EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below + OBSEntityID.setEntity(2); + OBSEntityID.setApplication(1); + OBSEntityID.setSite(1); + + EntityID TGTEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below + TGTEntityID.setEntity(3); + TGTEntityID.setApplication(1); + TGTEntityID.setSite(1); + + /* BELOW IS THE RECIEVE CODE // + // // + // // + */ // + PduFactory factory; + MulticastSocket socket = null; + InetAddress address = null; + DatagramPacket packet; + short currentPduType = 0; //will use the curentPduType as the check for sending other packets. + + try { + System.out.println("FDC is alive and ready to recieve fire missions...\n\n"); + socket = new MulticastSocket(MULTICAST_PORT); + address = InetAddress.getByName(MULTICAST_GROUP); + socket.joinGroup(address); + + factory = new PduFactory(); + + while (true) // Loop infinitely, receiving datagrams + { + byte buffer[] = new byte[1500]; // typical MTU size + + packet = new DatagramPacket(buffer, buffer.length); // reset + + socket.receive(packet); + + String marking2 = new String(); + Pdu pdu = factory.createPdu(packet.getData()); + currentPduType = pdu.getPduType(); + if (currentPduType == 14) //stop/freeze PDU + { + System.out.println("recieved Stop/Freeze packet..."); + return; + } +// pdu.setExerciseID((short)5); + if (pdu != null) { + if (sentBufferList.contains(pdu.getTimestamp())) { + pdu = null; + } + if (pdu != null) { + + String currentPduTypeName = pdu.getClass().getName(); + + if (currentPduType == 1) { + EntityStatePdu pdu2 = (EntityStatePdu) pdu; + marking2 = pdu2.getMarking().getCharactersString(); + } + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU: "); + message.append("pduType "); + if (currentPduType < 10) { + message.append(" "); + } + message.append(currentPduType).append(" ").append(currentPduTypeName); + message.append(" "); + message.append(marking2); + System.out.println(message.toString()); + //Reference for PDU Types: + // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm + // + + if (currentPduType == 1) //EntityState + { + EntityStatePdu entityPDU = (EntityStatePdu) pdu; + EntityType PduEntityType = entityPDU.getEntityType(); + if (PduEntityType.getCountry() == 225) { + Thread.sleep((long) 200); + timestamp = disTime.getDisAbsoluteTimestamp(); + FDCespdu.setTimestamp(timestamp); + System.out.println("Talking to the Observer, sending a radio check "); + sender.run(FDCespdu); + } + } + if (currentPduType == 16) //Action request + { + // Action response is sending a Null PDU, not sure why... + AcknowledgePdu ack = new AcknowledgePdu(); + ack.setExerciseID((short) 1); + ack.setRequestID((long) 1); + timestamp = disTime.getDisAbsoluteTimestamp(); + ack.setTimestamp(timestamp); + + FirePdu fire = new FirePdu(); + fire.setExerciseID((short) 1); + fire.setFireMissionIndex(1000); + fire.setRangeToTarget((float) Math.sqrt(Math.pow(150, 2) + Math.pow(150, 2))); //would pass in target info, but here we know location of tgt is (150,150) and FDC (0,0) + fire.setFiringEntityID(FDCID); + fire.setTargetEntityID(TGTEntityID); + timestamp = disTime.getDisAbsoluteTimestamp(); + fire.setTimestamp(timestamp); + sender.run(ack, fire); + } + + if (currentPduType == 22) //Comment PDU + { + AcknowledgePdu ack = new AcknowledgePdu(); + ack.setExerciseID((short) 1); + ack.setRequestID((long) 1); + timestamp = disTime.getDisAbsoluteTimestamp(); + ack.setTimestamp(timestamp); + + StopFreezePdu stop = new StopFreezePdu(); + stop.setExerciseID((short) 1); + stop.setRequestID((long) 1); + sender.run(ack, stop); + } + + } else { + System.out.println("received packet but pdu is null and originated from FDC. Still standing by..."); + } + } + } + } catch (IOException e) { + System.out.println("Problem with FDC.PduReceiver, see exception trace:"); + System.out.println(e); + } finally { + System.out.println("FDC.PduReceiver complete. - OUT!"); + } + + } + +} diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/FriscoFurrPduSender.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/FriscoFurrPduSender.java index 6a5a617d8f3568db57748290b128cf90019cb3c2..d1b27987e930224df64c255ea29a1bde9bea4c50 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/FriscoFurrPduSender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/FriscoFurrPduSender.java @@ -1,226 +1,230 @@ -package MV3500Cohort2018JulySeptember.projects.FriscoFurr.originals; - -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis.*; // OpenDIS version 4 -import edu.nps.moves.disenum.*; -import edu.nps.moves.examples.ClassNameComparator; - - -/** - * This is an example that sends many/most types of PDUs. Useful for testing standards - * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. - * Adapted from OpenDIS library example package edu.nps.moves.examples - * - * @author DMcG - * @version $Id:$ - */ -public class FriscoFurrPduSender -{ - /** Default multicast group address we send on. */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - - /** Default multicast port used, matches Wireshark DIS capture default */ - public static final int DEFAULT_MULTICAST_PORT = 3000; - - private int port; - InetAddress multicastAddress; - - public FriscoFurrPduSender(int port, String multicast) { - try - { - this.port = port; - multicastAddress = InetAddress.getByName(multicast); - if (!multicastAddress.isMulticastAddress()) - { - System.out.println("Not a multicast address: " + multicast); - } - } - catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); - } - } - - public void run() - { - System.out.println("DisExamples.PduSender started..."); - try { - List<Pdu> generatedPdus = new ArrayList<>(); - - // Loop through all the enumerated PDU types, create a PDU for each type, - // and add that PDU to a list. - System.out.println("number of PDU types in pduType is " + PduType.values().length); - for (PduType pdu : PduType.values()) { - Pdu aPdu = null; - System.out.println(pdu); - switch (pdu) // using enumeration values from edu.nps.moves.disenum.* - { -// -// case ENTITY_STATE: -// System.out.println("Case: Enitity_State "+pdu+"\n"); -// aPdu = new EntityStatePdu(); -// EntityStatePdu espdu = (EntityStatePdu) aPdu; -// Marking marking = new Marking(); -// marking.setCharactersString("TEST DUDE"); -// espdu.setMarking(marking); -// Vector3Double espduLocation = new Vector3Double(); -// espduLocation.setX(1.0); -// espduLocation.setY(2.0); -// espduLocation.setZ(3.0); -// EntityType entityType = espdu.getEntityType(); -// entityType.setCountry(222); -// -// break; - -// case COMMENT: -// aPdu = new CommentPdu(); -// CommentPdu comment = (CommentPdu) aPdu; -// EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below -// OBSEntityID.setEntity(2); -// OBSEntityID.setApplication(1); -// OBSEntityID.setSite(1); -// comment.setOriginatingEntityID(OBSEntityID); -// -// long number = 1; -// //comment.setNumberOfFixedDatumRecords(number); -// -// comment.setNumberOfVariableDatumRecords(number); -// List datum = new ArrayList<FixedDatum>(); -// FixedDatum superDatum = new FixedDatum(); -// superDatum.setFixedDatumID((long)5); -// superDatum.setFixedDatumValue((long) 54321); -// datum.add(10); -// datum.add(superDatum); -// comment.setFixedDatums(datum); -// List Vdatum = new ArrayList<VariableDatum>(); -// VariableDatum testBitch = new VariableDatum(); -// testBitch.setVariableDatumID(1); -// Vdatum.add(15); -// comment.setVariableDatums(Vdatum); -// break; - -// case FIRE: -// aPdu = new FirePdu(); -// break; - - case DETONATION: - aPdu = new DetonationPdu(); - System.out.println("detonationPdu type " + aPdu.getPduType()); - break; -// -// case COLLISION: -// aPdu = new CollisionPdu(); -// break; -// -// case SERVICE_REQUEST: -// aPdu = new ServiceRequestPdu(); -// break; -// -// case RESUPPLY_OFFER: -// aPdu = new ResupplyOfferPdu(); -// break; -// -// case RESUPPLY_RECEIVED: -// aPdu = new ResupplyReceivedPdu(); -// break; -// -// case RESUPPLY_CANCEL: -// aPdu = new ResupplyCancelPdu(); -// break; -// -// case REPAIR_COMPLETE: -// aPdu = new RepairCompletePdu(); -// break; -// -// case REPAIR_RESPONSE: -// aPdu = new RepairResponsePdu(); -// break; -// -// case CREATE_ENTITY: -// aPdu = new CreateEntityPdu(); -// break; -// -// case REMOVE_ENTITY: -// aPdu = new RemoveEntityPdu(); -// break; -// -// case START_RESUME: -// aPdu = new StartResumePdu(); -// break; -// -// case STOP_FREEZE: -// aPdu = new StopFreezePdu(); -// break; -// -// case ACKNOWLEDGE: -// aPdu = new AcknowledgePdu(); -// break; -// -// case ACTION_REQUEST: -// aPdu = new ActionRequestPdu(); -// ActionRequestPdu action = (ActionRequestPdu) aPdu; -// EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below -// OBSEntityID.setEntity(2); -// OBSEntityID.setApplication(1); -// OBSEntityID.setSite(1); -// action.setOriginatingEntityID(OBSEntityID); -// break; - - default: - System.out.print("PDU of type " + pdu + " not supported, created or sent "); - System.out.println(); - } - if (aPdu != null) - { - generatedPdus.add(aPdu); - System.out.println("APDU container count "+generatedPdus.size()); - } - } - - // Sort the created PDUs by class name - Collections.sort(generatedPdus, new ClassNameComparator()); - - // Send the PDUs we created - InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); - socket.joinGroup(localMulticastAddress); - - for (int idx = 0; idx < generatedPdus.size(); idx++) - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - byte[] buffer; - - Pdu aPdu = generatedPdus.get(idx); - aPdu.marshal(dos); - - buffer = baos.toByteArray(); - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); - socket.send(packet); - System.out.println("Sent PDU of type " + aPdu.getClass().getName()); - } - // write the PDUs out to an XML file. - //PduContainer container = new PduContainer(); - //container.setPdus(generatedPdus); - //container.marshallToXml("examplePdus.xml"); - } catch (IOException e) - { - System.out.println(e); - } - } - - public static void main(String args[]) - { - if (args.length == 2) { - FriscoFurrPduSender sender = new FriscoFurrPduSender(Integer.parseInt(args[0]), args[1]); - sender.run(); - } else { - System.out.println("Usage: PduSender <port> <multicast group>"); - System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); - FriscoFurrPduSender sender = new FriscoFurrPduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); - sender.run(); - } - } -} +package MV3500Cohort2018JulySeptember.projects.FriscoFurr.originals; + +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis.*; // OpenDIS version 4 +import edu.nps.moves.disenum.*; +import edu.nps.moves.examples.ClassNameComparator; + + +/** + * This is an example that sends many/most types of PDUs. Useful for testing standards + * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. + * Adapted from OpenDIS library example package edu.nps.moves.examples + * + * @author DMcG + * @version $Id:$ + */ +public class FriscoFurrPduSender +{ + /** Default multicast group address we send on. */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; + + /** Default multicast port used, matches Wireshark DIS capture default */ + public static final int DEFAULT_MULTICAST_PORT = 3000; + + private int port; + InetAddress multicastAddress; + + public FriscoFurrPduSender(int port, String multicast) { + try + { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) + { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run() + { + System.out.println("DisExamples.PduSender started..."); + try { + List<Pdu> generatedPdus = new ArrayList<>(); + + // Loop through all the enumerated PDU types, create a PDU for each type, + // and add that PDU to a list. + System.out.println("number of PDU types in pduType is " + PduType.values().length); + for (PduType pdu : PduType.values()) { + Pdu aPdu = null; + System.out.println(pdu); + switch (pdu) // using enumeration values from edu.nps.moves.disenum.* + { +// +// case ENTITY_STATE: +// System.out.println("Case: Enitity_State "+pdu+"\n"); +// aPdu = new EntityStatePdu(); +// EntityStatePdu espdu = (EntityStatePdu) aPdu; +// Marking marking = new Marking(); +// marking.setCharactersString("TEST DUDE"); +// espdu.setMarking(marking); +// Vector3Double espduLocation = new Vector3Double(); +// espduLocation.setX(1.0); +// espduLocation.setY(2.0); +// espduLocation.setZ(3.0); +// EntityType entityType = espdu.getEntityType(); +// entityType.setCountry(222); +// +// break; + +// case COMMENT: +// aPdu = new CommentPdu(); +// CommentPdu comment = (CommentPdu) aPdu; +// EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below +// OBSEntityID.setEntity(2); +// OBSEntityID.setApplication(1); +// OBSEntityID.setSite(1); +// comment.setOriginatingEntityID(OBSEntityID); +// +// long number = 1; +// //comment.setNumberOfFixedDatumRecords(number); +// +// comment.setNumberOfVariableDatumRecords(number); +// List datum = new ArrayList<FixedDatum>(); +// FixedDatum superDatum = new FixedDatum(); +// superDatum.setFixedDatumID((long)5); +// superDatum.setFixedDatumValue((long) 54321); +// datum.add(10); +// datum.add(superDatum); +// comment.setFixedDatums(datum); +// List Vdatum = new ArrayList<VariableDatum>(); +// VariableDatum testBitch = new VariableDatum(); +// testBitch.setVariableDatumID(1); +// Vdatum.add(15); +// comment.setVariableDatums(Vdatum); +// break; + +// case FIRE: +// aPdu = new FirePdu(); +// break; + + case DETONATION: + aPdu = new DetonationPdu(); + System.out.println("detonationPdu type " + aPdu.getPduType()); + break; +// +// case COLLISION: +// aPdu = new CollisionPdu(); +// break; +// +// case SERVICE_REQUEST: +// aPdu = new ServiceRequestPdu(); +// break; +// +// case RESUPPLY_OFFER: +// aPdu = new ResupplyOfferPdu(); +// break; +// +// case RESUPPLY_RECEIVED: +// aPdu = new ResupplyReceivedPdu(); +// break; +// +// case RESUPPLY_CANCEL: +// aPdu = new ResupplyCancelPdu(); +// break; +// +// case REPAIR_COMPLETE: +// aPdu = new RepairCompletePdu(); +// break; +// +// case REPAIR_RESPONSE: +// aPdu = new RepairResponsePdu(); +// break; +// +// case CREATE_ENTITY: +// aPdu = new CreateEntityPdu(); +// break; +// +// case REMOVE_ENTITY: +// aPdu = new RemoveEntityPdu(); +// break; +// +// case START_RESUME: +// aPdu = new StartResumePdu(); +// break; +// +// case STOP_FREEZE: +// aPdu = new StopFreezePdu(); +// break; +// +// case ACKNOWLEDGE: +// aPdu = new AcknowledgePdu(); +// break; +// +// case ACTION_REQUEST: +// aPdu = new ActionRequestPdu(); +// ActionRequestPdu action = (ActionRequestPdu) aPdu; +// EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below +// OBSEntityID.setEntity(2); +// OBSEntityID.setApplication(1); +// OBSEntityID.setSite(1); +// action.setOriginatingEntityID(OBSEntityID); +// break; + + default: + System.out.print("PDU of type " + pdu + " not supported, created or sent "); + System.out.println(); + } + if (aPdu != null) + { + generatedPdus.add(aPdu); + System.out.println("APDU container count "+generatedPdus.size()); + } + } + + // Sort the created PDUs by class name + Collections.sort(generatedPdus, new ClassNameComparator()); + + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (int idx = 0; idx < generatedPdus.size(); idx++) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdus.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + System.out.println("Sent PDU of type " + aPdu.getClass().getName()); + } + // write the PDUs out to an XML file. + //PduContainer container = new PduContainer(); + //container.setPdus(generatedPdus); + //container.marshallToXml("examplePdus.xml"); + } catch (IOException e) + { + System.out.println(e); + } + } + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String args[]) + { + if (args.length == 2) { + FriscoFurrPduSender sender = new FriscoFurrPduSender(Integer.parseInt(args[0]), args[1]); + sender.run(); + } else { + System.out.println("Usage: PduSender <port> <multicast group>"); + System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + FriscoFurrPduSender sender = new FriscoFurrPduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(); + } + } +} diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/OBSSendRecieve1.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/OBSSendRecieve1.java index 306f731956de6c3eb870725b28ebe3eb16c8d7a7..e13f643c986984f55f2e086bd193cb0d7507bfed 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/OBSSendRecieve1.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/OBSSendRecieve1.java @@ -1,310 +1,312 @@ -package MV3500Cohort2018JulySeptember.projects.FriscoFurr.originals; - -import java.net.*; -import java.io.*; -import java.util.*; -import edu.nps.moves.dis.*; // OpenDIS version 4 -import java.io.IOException; -import edu.nps.moves.disutil.PduFactory; -import edu.nps.moves.disutil.DisTime; - -public class OBSSendRecieve1 { - - /** - * Default multicast group address we send on. - */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - - /** - * Default multicast port used, matches Wireshark DIS capture default - */ - public static final int DEFAULT_MULTICAST_PORT = 3000; - - private int port; - InetAddress multicastAddress; - - public static final int MULTICAST_PORT = 3000; - public static final String MULTICAST_GROUP = "239.1.2.3"; - public static final boolean USE_FAST_ESPDU = false; - public long[] sentBuffer = new long[100]; - public static List sentBufferList; - DisTime disTime = DisTime.getInstance(); - int transmission =1; - - public OBSSendRecieve1(int port, String multicast) { - this.sentBufferList = new ArrayList<>(); - try { - this.port = port; - multicastAddress = InetAddress.getByName(multicast); - if (!multicastAddress.isMulticastAddress()) { - System.out.println("Not a multicast address: " + multicast); - } - } catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); - } - } - - public void run(Pdu... pdupass) throws UnknownHostException, IOException { - - List<Pdu> generatedPdus = new ArrayList<>(); - Pdu aPdu = null; - if(transmission ==1){ - System.out.println("\nInitalizing OP coms..."); - transmission++; - } - if(transmission>1){ - System.out.println("\nObserver Sending traffic..."); - } - // Send the PDUs we created - InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); - socket.joinGroup(localMulticastAddress); - - for (Pdu i : pdupass) { - Pdu pdu = i; - if (sentBufferList.contains(pdu.getTimestamp())) { - break; - } - - short currentPduType = pdu.getPduType(); - System.out.println("in observer sender, processing PDU type: " + currentPduType); -// String currentPduTypeName = pdu.getClass().getName(); -// short currentProtocolFamilyID = pdu.getProtocolFamily(); -// String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); - - // Loop through all the enumerated PDU types, create a PDU for each type, - // and add that PDU to a list. - //System.out.println(pdu); - //Change the switch statement to the currentPduType from the recieve portion, then when a packet we want comes in, send the CASE file. - switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* - { - - case 1: //ENTITY_STATE: - aPdu = pdu; - break; - -// case COMMENT: -// aPdu = new CommentPdu(); -// break; -// -// case 2: //FIRE -// aPdu = pdu; -// break; -// -// case DETONATION: -// aPdu = new DetonationPdu(); -// break; -// -// case 15: //AcknowledgePdu -// aPdu = pdu; -// break; -//// - case 16: //ACTION_REQUEST: - aPdu = new ActionRequestPdu(); - break; - - case 22: //CommentPdu - aPdu = pdu; - break; - -// case 14: -// aPdu = pdu; -// break; - default: - //add some shit that makes sense here. - System.out.print("PDU of type " + pdu + " not supported by Observer, created or sent "); - System.out.println(); - } - if (aPdu != null) { - generatedPdus.add(aPdu); - System.out.println("APDU container count " + generatedPdus.size()); - } - - } - for (int idx = 0; idx < generatedPdus.size(); idx++) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - byte[] buffer; - - aPdu = generatedPdus.get(idx); - aPdu.marshal(dos); - - buffer = baos.toByteArray(); - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); - socket.send(packet); - //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); - sentBufferList.add(aPdu.getTimestamp()); - System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName()+"/n"); - } - } - - public static void main(String[] args) throws IOException { - DisTime disTime = DisTime.getInstance(); - //turns on the sender code - might need to move around down into the recieve with the if statements... - // - // ORIGINAL SENDING CODE MAIN CLASS: - // - // -// if (args.length == 2) { -// FDCSendRecieve sender = new FDCSendRecieve(Integer.parseInt(args[0]), args[1]); -// // sender.run(); //needs to be sender.run(pdu) -// } else { -// System.out.println("Usage: PduSender <port> <multicast group>"); -// System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); -// FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); - // sender.run(); -// } - - // - // Inital Hello world from entity: - // - OBSSendRecieve1 sender = new OBSSendRecieve1(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender - - EntityStatePdu OBSespdu = new EntityStatePdu(); - Marking marking = new Marking(); - marking.setCharactersString("Observer"); - OBSespdu.setMarking(marking); - OBSespdu.setExerciseID((short) 1); - EntityID OBSID = OBSespdu.getEntityID(); - OBSID.setSite(1); // 0 is apparently not a valid site number, per the spec - OBSID.setApplication(1); - OBSID.setEntity(2); //change for each person I think??? - JMF - EntityType entityType = OBSespdu.getEntityType(); - // - //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 - // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 - // - entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 - entityType.setCountry(225); // USA TGT = 222 (Russia), OBS = 225 - entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 - entityType.setCategory((short) 40); // FDC TGT = 1, Tank OBS=40 OP -// entityType.setSubcategory((short) 12); // M1068 TGT = 2, T72 tank NONE FOR OP -// entityType.setSpec((short) 1); // M1068 w/ SICUP Tent NONE FOR TGT OR OP - Vector3Double location = new Vector3Double(); - location.setX(75.0); //TGT = 150 OBS = 75 - location.setY(75.0); //TGT = 150 OBS = 75 - location.setZ(50.0); //TGT = 20 OBS = 50 - OBSespdu.setEntityLocation(location); - int timestamp = disTime.getDisAbsoluteTimestamp(); - OBSespdu.setTimestamp(timestamp); - //FDCespdu.setTimestamp(System.currentTimeMillis()); - sender.run(OBSespdu); //sends inital here I am and who I am - - //other player to look out for: - EntityID FDCEntityID = new EntityID(); - FDCEntityID.setEntity(1); - FDCEntityID.setApplication(1); - FDCEntityID.setSite(1); - - EntityID TGTEntityID = new EntityID(); - TGTEntityID.setEntity(3); - TGTEntityID.setApplication(1); - TGTEntityID.setSite(1); - - /* BELOW IS THE RECIEVE CODE // - // // - // // - */ // - PduFactory factory; - MulticastSocket socket = null; - InetAddress address = null; - DatagramPacket packet; - short currentPduType; //will use the curentPduType as the check for sending other packets. - - try { - // TODO: Change the line below to make sense for each class - System.out.println("Observer is in the OP and looking for targets...\n\n"); - socket = new MulticastSocket(MULTICAST_PORT); - address = InetAddress.getByName(MULTICAST_GROUP); - socket.joinGroup(address); - - factory = new PduFactory(); - - while (true) // Loop infinitely, receiving datagrams - { - byte buffer[] = new byte[1500]; // typical MTU size - - packet = new DatagramPacket(buffer, buffer.length); // reset - - socket.receive(packet); - // - //TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE. - // - - String marking2 = new String(); - Pdu pdu = factory.createPdu(packet.getData()); - currentPduType = pdu.getPduType(); - if (currentPduType == 14) //stop/freeze PDU - { - System.out.println("recieved Stop/Freeze packet..."); - return; - } -// pdu.setExerciseID((short)5); - if (pdu != null) { - if (sentBufferList.contains(pdu.getTimestamp())) { - pdu = null; - } - if (pdu != null) { - - String currentPduTypeName = pdu.getClass().getName(); - if (currentPduType == 1) { - EntityStatePdu pdu2 = (EntityStatePdu) pdu; - marking2 = pdu2.getMarking().getCharactersString(); - } -//Keep adding any if statements as needed for the class you are building. - StringBuilder message = new StringBuilder(); - message.append("received DIS PDU: "); - message.append("pduType "); - if (currentPduType < 10) { - message.append(" "); - } - message.append(currentPduType).append(" ").append(currentPduTypeName); - message.append(" "); - message.append(marking2); - System.out.println(message.toString()); - //Reference for PDU Types: - // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm - // - - if (currentPduType == 1) //EntityState - { - EntityStatePdu entityPDU = (EntityStatePdu) pdu; - EntityType PduEntityType = entityPDU.getEntityType(); - if (PduEntityType.getCountry() == 222) { - ActionRequestPdu action = new ActionRequestPdu(); - action.setExerciseID((short) 1); - action.setRequestID((long) 2); - action.setOriginatingEntityID(OBSID); - action.setReceivingEntityID(FDCEntityID); - timestamp = disTime.getDisAbsoluteTimestamp(); - action.setTimestamp(timestamp); - System.out.println("\n Got a Russian SOB! Preparing CFF to send."); - sender.run(action); - } - } - - if (currentPduType == 3) //Detination - { - CommentPdu comment = new CommentPdu(); - comment.setExerciseID((short) 1); - comment.setOriginatingEntityID(TGTEntityID); - timestamp = disTime.getDisAbsoluteTimestamp(); - comment.setTimestamp(timestamp); - sender.run(comment); - } - - } else { - System.out.println("received packet but pdu is null and originated from Observer. Still searching for other Targets..."); - } - } - } - } catch (IOException e) { - System.out.println("Problem with Observer.PduReceiver, see exception trace:"); - System.out.println(e); - } finally { - System.out.println("Observer.PduReceiver complete. - OUT!"); - } - - } - -} +package MV3500Cohort2018JulySeptember.projects.FriscoFurr.originals; + +import java.net.*; +import java.io.*; +import java.util.*; +import edu.nps.moves.dis.*; // OpenDIS version 4 +import java.io.IOException; +import edu.nps.moves.disutil.PduFactory; +import edu.nps.moves.disutil.DisTime; + +public class OBSSendRecieve1 { + + /** + * Default multicast group address we send on. + */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; + + /** + * Default multicast port used, matches Wireshark DIS capture default + */ + public static final int DEFAULT_MULTICAST_PORT = 3000; + + private int port; + InetAddress multicastAddress; + + /** socket parameter of interest */ + public static final int MULTICAST_PORT = 3000; + /** socket parameter of interest */ + public static final String MULTICAST_GROUP = "239.1.2.3"; + static final boolean USE_FAST_ESPDU = false; + private long[] sentBuffer = new long[100]; + private static List sentBufferList; + DisTime disTime = DisTime.getInstance(); + int transmission =1; + + public OBSSendRecieve1(int port, String multicast) { + this.sentBufferList = new ArrayList<>(); + try { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) { + System.out.println("Not a multicast address: " + multicast); + } + } catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run(Pdu... pdupass) throws UnknownHostException, IOException { + + List<Pdu> generatedPdus = new ArrayList<>(); + Pdu aPdu = null; + if(transmission ==1){ + System.out.println("\nInitalizing OP coms..."); + transmission++; + } + if(transmission>1){ + System.out.println("\nObserver Sending traffic..."); + } + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (Pdu i : pdupass) { + Pdu pdu = i; + if (sentBufferList.contains(pdu.getTimestamp())) { + break; + } + + short currentPduType = pdu.getPduType(); + System.out.println("in observer sender, processing PDU type: " + currentPduType); +// String currentPduTypeName = pdu.getClass().getName(); +// short currentProtocolFamilyID = pdu.getProtocolFamily(); +// String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + + // Loop through all the enumerated PDU types, create a PDU for each type, + // and add that PDU to a list. + //System.out.println(pdu); + //Change the switch statement to the currentPduType from the recieve portion, then when a packet we want comes in, send the CASE file. + switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* + { + + case 1: //ENTITY_STATE: + aPdu = pdu; + break; + +// case COMMENT: +// aPdu = new CommentPdu(); +// break; +// +// case 2: //FIRE +// aPdu = pdu; +// break; +// +// case DETONATION: +// aPdu = new DetonationPdu(); +// break; +// +// case 15: //AcknowledgePdu +// aPdu = pdu; +// break; +//// + case 16: //ACTION_REQUEST: + aPdu = new ActionRequestPdu(); + break; + + case 22: //CommentPdu + aPdu = pdu; + break; + +// case 14: +// aPdu = pdu; +// break; + default: + //add some shit that makes sense here. + System.out.print("PDU of type " + pdu + " not supported by Observer, created or sent "); + System.out.println(); + } + if (aPdu != null) { + generatedPdus.add(aPdu); + System.out.println("APDU container count " + generatedPdus.size()); + } + + } + for (int idx = 0; idx < generatedPdus.size(); idx++) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + aPdu = generatedPdus.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); + sentBufferList.add(aPdu.getTimestamp()); + System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName()+"/n"); + } + } + + public static void main(String[] args) throws IOException { + DisTime disTime = DisTime.getInstance(); + //turns on the sender code - might need to move around down into the recieve with the if statements... + // + // ORIGINAL SENDING CODE MAIN CLASS: + // + // +// if (args.length == 2) { +// FDCSendRecieve sender = new FDCSendRecieve(Integer.parseInt(args[0]), args[1]); +// // sender.run(); //needs to be sender.run(pdu) +// } else { +// System.out.println("Usage: PduSender <port> <multicast group>"); +// System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); +// FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + // sender.run(); +// } + + // + // Inital Hello world from entity: + // + OBSSendRecieve1 sender = new OBSSendRecieve1(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender + + EntityStatePdu OBSespdu = new EntityStatePdu(); + Marking marking = new Marking(); + marking.setCharactersString("Observer"); + OBSespdu.setMarking(marking); + OBSespdu.setExerciseID((short) 1); + EntityID OBSID = OBSespdu.getEntityID(); + OBSID.setSite(1); // 0 is apparently not a valid site number, per the spec + OBSID.setApplication(1); + OBSID.setEntity(2); //change for each person I think??? - JMF + EntityType entityType = OBSespdu.getEntityType(); + // + //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 + // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 + // + entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 + entityType.setCountry(225); // USA TGT = 222 (Russia), OBS = 225 + entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 + entityType.setCategory((short) 40); // FDC TGT = 1, Tank OBS=40 OP +// entityType.setSubcategory((short) 12); // M1068 TGT = 2, T72 tank NONE FOR OP +// entityType.setSpec((short) 1); // M1068 w/ SICUP Tent NONE FOR TGT OR OP + Vector3Double location = new Vector3Double(); + location.setX(75.0); //TGT = 150 OBS = 75 + location.setY(75.0); //TGT = 150 OBS = 75 + location.setZ(50.0); //TGT = 20 OBS = 50 + OBSespdu.setEntityLocation(location); + int timestamp = disTime.getDisAbsoluteTimestamp(); + OBSespdu.setTimestamp(timestamp); + //FDCespdu.setTimestamp(System.currentTimeMillis()); + sender.run(OBSespdu); //sends inital here I am and who I am + + //other player to look out for: + EntityID FDCEntityID = new EntityID(); + FDCEntityID.setEntity(1); + FDCEntityID.setApplication(1); + FDCEntityID.setSite(1); + + EntityID TGTEntityID = new EntityID(); + TGTEntityID.setEntity(3); + TGTEntityID.setApplication(1); + TGTEntityID.setSite(1); + + /* BELOW IS THE RECIEVE CODE // + // // + // // + */ // + PduFactory factory; + MulticastSocket socket = null; + InetAddress address = null; + DatagramPacket packet; + short currentPduType; //will use the curentPduType as the check for sending other packets. + + try { + // TODO: Change the line below to make sense for each class + System.out.println("Observer is in the OP and looking for targets...\n\n"); + socket = new MulticastSocket(MULTICAST_PORT); + address = InetAddress.getByName(MULTICAST_GROUP); + socket.joinGroup(address); + + factory = new PduFactory(); + + while (true) // Loop infinitely, receiving datagrams + { + byte buffer[] = new byte[1500]; // typical MTU size + + packet = new DatagramPacket(buffer, buffer.length); // reset + + socket.receive(packet); + // + //TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE. + // + + String marking2 = new String(); + Pdu pdu = factory.createPdu(packet.getData()); + currentPduType = pdu.getPduType(); + if (currentPduType == 14) //stop/freeze PDU + { + System.out.println("recieved Stop/Freeze packet..."); + return; + } +// pdu.setExerciseID((short)5); + if (pdu != null) { + if (sentBufferList.contains(pdu.getTimestamp())) { + pdu = null; + } + if (pdu != null) { + + String currentPduTypeName = pdu.getClass().getName(); + if (currentPduType == 1) { + EntityStatePdu pdu2 = (EntityStatePdu) pdu; + marking2 = pdu2.getMarking().getCharactersString(); + } +//Keep adding any if statements as needed for the class you are building. + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU: "); + message.append("pduType "); + if (currentPduType < 10) { + message.append(" "); + } + message.append(currentPduType).append(" ").append(currentPduTypeName); + message.append(" "); + message.append(marking2); + System.out.println(message.toString()); + //Reference for PDU Types: + // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm + // + + if (currentPduType == 1) //EntityState + { + EntityStatePdu entityPDU = (EntityStatePdu) pdu; + EntityType PduEntityType = entityPDU.getEntityType(); + if (PduEntityType.getCountry() == 222) { + ActionRequestPdu action = new ActionRequestPdu(); + action.setExerciseID((short) 1); + action.setRequestID((long) 2); + action.setOriginatingEntityID(OBSID); + action.setReceivingEntityID(FDCEntityID); + timestamp = disTime.getDisAbsoluteTimestamp(); + action.setTimestamp(timestamp); + System.out.println("\n Got a Russian SOB! Preparing CFF to send."); + sender.run(action); + } + } + + if (currentPduType == 3) //Detination + { + CommentPdu comment = new CommentPdu(); + comment.setExerciseID((short) 1); + comment.setOriginatingEntityID(TGTEntityID); + timestamp = disTime.getDisAbsoluteTimestamp(); + comment.setTimestamp(timestamp); + sender.run(comment); + } + + } else { + System.out.println("received packet but pdu is null and originated from Observer. Still searching for other Targets..."); + } + } + } + } catch (IOException e) { + System.out.println("Problem with Observer.PduReceiver, see exception trace:"); + System.out.println(e); + } finally { + System.out.println("Observer.PduReceiver complete. - OUT!"); + } + + } + +} diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/TGTSendRecieve.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/TGTSendRecieve.java index 7a218265fb2b255824daf667fc036cb67709bc74..f096673607c67f3bfe41e24664b495b9bf7cb5dd 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/TGTSendRecieve.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/originals/TGTSendRecieve.java @@ -1,250 +1,252 @@ -package MV3500Cohort2018JulySeptember.projects.FriscoFurr.originals; - -import java.net.*; -import java.io.*; -import java.util.*; -import edu.nps.moves.dis.*; // OpenDIS version 4 -import java.io.IOException; -import edu.nps.moves.disutil.PduFactory; -import edu.nps.moves.disutil.DisTime; - -public class TGTSendRecieve { - - /** - * Default multicast group address we send on. - */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - - /** - * Default multicast port used, matches Wireshark DIS capture default - */ - public static final int DEFAULT_MULTICAST_PORT = 3000; - - private int port; - InetAddress multicastAddress; - - public static final int MULTICAST_PORT = 3000; - public static final String MULTICAST_GROUP = "239.1.2.3"; - public static final boolean USE_FAST_ESPDU = false; - public long[] sentBuffer = new long[100]; - public static List sentBufferList; - DisTime disTime = DisTime.getInstance(); - int transmission = 1; - - public TGTSendRecieve(int port, String multicast) { - this.sentBufferList = new ArrayList<>(); - try { - this.port = port; - multicastAddress = InetAddress.getByName(multicast); - if (!multicastAddress.isMulticastAddress()) { - System.out.println("Not a multicast address: " + multicast); - } - } catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); - } - } - - public void run(Pdu... pdupass) throws UnknownHostException, IOException { - - List<Pdu> generatedPdus = new ArrayList<>(); - Pdu aPdu = null; - if (transmission == 1) { - System.out.println("\nTarget is rolling out..."); - transmission++; - } - if (transmission > 1) { - System.out.println("\nDeath from above everywhere! (sending function started)..."); - } - // Send the PDUs we created - InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); - socket.joinGroup(localMulticastAddress); - - for (Pdu i : pdupass) { - Pdu pdu = i; - if (sentBufferList.contains(pdu.getTimestamp())) { - break; - } - - short currentPduType = pdu.getPduType(); - System.out.println("in Target sender, processing PDU type: " + currentPduType); -// - switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* - { - - case 1: //ENTITY_STATE: - aPdu = pdu; - break; - - case 3: //detination PDU - aPdu = pdu; - break; - - default: - //add some shit that makes sense here. - System.out.print("PDU of type " + pdu + " not supported by Observer, created or sent "); - System.out.println(); - } - if (aPdu != null) { - generatedPdus.add(aPdu); - System.out.println("APDU container count " + generatedPdus.size()); - } - - } - for (int idx = 0; idx < generatedPdus.size(); idx++) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - byte[] buffer; - - aPdu = generatedPdus.get(idx); - aPdu.marshal(dos); - - buffer = baos.toByteArray(); - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); - socket.send(packet); - //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); - sentBufferList.add(aPdu.getTimestamp()); - System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName() + "/n"); - } - } - - public static void main(String[] args) throws IOException { - DisTime disTime = DisTime.getInstance(); - //turns on the sender code - might need to move around down into the recieve with the if statements... - - // - // Inital Hello world from entity: - // - TGTSendRecieve sender = new TGTSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender - - EntityStatePdu TGTespdu = new EntityStatePdu(); - Marking marking = new Marking(); - marking.setCharactersString("Target"); - TGTespdu.setMarking(marking); - TGTespdu.setExerciseID((short) 1); - EntityID OBSID = TGTespdu.getEntityID(); - OBSID.setSite(1); // 0 is apparently not a valid site number, per the spec - OBSID.setApplication(1); - OBSID.setEntity(3); //change for each person I think??? - JMF - EntityType entityType = TGTespdu.getEntityType(); - // - //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 - // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 - // - entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 - entityType.setCountry(222); // USA TGT = 222 (Russia), OBS = 225 - entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 - entityType.setCategory((short) 1); // FDC TGT = 1, Tank OBS=40 OP - entityType.setSubcategory((short) 2); // M1068 TGT = 2, T72 tank NONE FOR OP - - Vector3Double location = new Vector3Double(); - location.setX(150.0); //TGT = 150 OBS = 75 - location.setY(150.0); //TGT = 150 OBS = 75 - location.setZ(20.0); //TGT = 20 OBS = 50 - TGTespdu.setEntityLocation(location); - int timestamp = disTime.getDisAbsoluteTimestamp(); - TGTespdu.setTimestamp(timestamp); - sender.run(TGTespdu); //sends inital here I am and who I am - - //other player to look out for: - EntityID FDCEntityID = new EntityID(); - FDCEntityID.setEntity(1); - FDCEntityID.setApplication(1); - FDCEntityID.setSite(1); - - EntityID OBSEntityID = new EntityID(); - OBSEntityID.setEntity(2); - OBSEntityID.setApplication(1); - OBSEntityID.setSite(1); - - /* BELOW IS THE RECIEVE CODE // - // // - // // - */ // - PduFactory factory; - MulticastSocket socket = null; - InetAddress address = null; - DatagramPacket packet; - short currentPduType; //will use the curentPduType as the check for sending other packets. - - try { - // TODO: Change the line below to make sense for each class - System.out.println("Russian T72 out on the prowl...\n\n"); - socket = new MulticastSocket(MULTICAST_PORT); - address = InetAddress.getByName(MULTICAST_GROUP); - socket.joinGroup(address); - - factory = new PduFactory(); - - while (true) // Loop infinitely, receiving datagrams - { - byte buffer[] = new byte[1500]; // typical MTU size - - packet = new DatagramPacket(buffer, buffer.length); // reset - - socket.receive(packet); - // - //TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE. - // - - String marking2 = new String(); - Pdu pdu = factory.createPdu(packet.getData()); - currentPduType = pdu.getPduType(); - if (currentPduType == 14) //stop/freeze PDU - { - System.out.println("recieved Stop/Freeze packet..."); - return; - } -// pdu.setExerciseID((short)5); - if (pdu != null) { - if (sentBufferList.contains(pdu.getTimestamp())) { - pdu = null; - } - if (pdu != null) { - - String currentPduTypeName = pdu.getClass().getName(); - if (currentPduType == 1) { - EntityStatePdu pdu2 = (EntityStatePdu) pdu; - marking2 = pdu2.getMarking().getCharactersString(); - } -//Keep adding any if statements as needed for the class you are building. - StringBuilder message = new StringBuilder(); - message.append("received DIS PDU: "); - message.append("pduType "); - if (currentPduType < 10) { - message.append(" "); - } - message.append(currentPduType).append(" ").append(currentPduTypeName); - message.append(" "); - message.append(marking2); - System.out.println(message.toString()); - //Reference for PDU Types: - // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm - // - - - if (currentPduType == 2) //FirePDU - { - DetonationPdu det = new DetonationPdu(); - det.setExerciseID((short) 1); - det.setDetonationResult((short)1); - timestamp = disTime.getDisAbsoluteTimestamp(); - det.setTimestamp(timestamp); - sender.run(det); - } - - } else { - System.out.println("received packet but pdu is null and originated from Target. Still doing sketchy Russian things..."); - } - } - } - } catch (IOException e) { - System.out.println("Problem with Target.PduReceiver, see exception trace:"); - System.out.println(e); - } finally { - System.out.println("Target.PduReceiver complete. - T-72 DESTROYED!"); - } - - } - -} +package MV3500Cohort2018JulySeptember.projects.FriscoFurr.originals; + +import java.net.*; +import java.io.*; +import java.util.*; +import edu.nps.moves.dis.*; // OpenDIS version 4 +import java.io.IOException; +import edu.nps.moves.disutil.PduFactory; +import edu.nps.moves.disutil.DisTime; + +public class TGTSendRecieve { + + /** + * Default multicast group address we send on. + */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; + + /** + * Default multicast port used, matches Wireshark DIS capture default + */ + public static final int DEFAULT_MULTICAST_PORT = 3000; + + private int port; + InetAddress multicastAddress; + + /** socket parameter of interest */ + public static final int MULTICAST_PORT = 3000; + /** socket parameter of interest */ + public static final String MULTICAST_GROUP = "239.1.2.3"; + static final boolean USE_FAST_ESPDU = false; + long[] sentBuffer = new long[100]; + static List sentBufferList; + DisTime disTime = DisTime.getInstance(); + int transmission = 1; + + public TGTSendRecieve(int port, String multicast) { + this.sentBufferList = new ArrayList<>(); + try { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) { + System.out.println("Not a multicast address: " + multicast); + } + } catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run(Pdu... pdupass) throws UnknownHostException, IOException { + + List<Pdu> generatedPdus = new ArrayList<>(); + Pdu aPdu = null; + if (transmission == 1) { + System.out.println("\nTarget is rolling out..."); + transmission++; + } + if (transmission > 1) { + System.out.println("\nDeath from above everywhere! (sending function started)..."); + } + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (Pdu i : pdupass) { + Pdu pdu = i; + if (sentBufferList.contains(pdu.getTimestamp())) { + break; + } + + short currentPduType = pdu.getPduType(); + System.out.println("in Target sender, processing PDU type: " + currentPduType); +// + switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* + { + + case 1: //ENTITY_STATE: + aPdu = pdu; + break; + + case 3: //detination PDU + aPdu = pdu; + break; + + default: + //add some shit that makes sense here. + System.out.print("PDU of type " + pdu + " not supported by Observer, created or sent "); + System.out.println(); + } + if (aPdu != null) { + generatedPdus.add(aPdu); + System.out.println("APDU container count " + generatedPdus.size()); + } + + } + for (int idx = 0; idx < generatedPdus.size(); idx++) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + aPdu = generatedPdus.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); + sentBufferList.add(aPdu.getTimestamp()); + System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName() + "/n"); + } + } + + public static void main(String[] args) throws IOException { + DisTime disTime = DisTime.getInstance(); + //turns on the sender code - might need to move around down into the recieve with the if statements... + + // + // Inital Hello world from entity: + // + TGTSendRecieve sender = new TGTSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender + + EntityStatePdu TGTespdu = new EntityStatePdu(); + Marking marking = new Marking(); + marking.setCharactersString("Target"); + TGTespdu.setMarking(marking); + TGTespdu.setExerciseID((short) 1); + EntityID OBSID = TGTespdu.getEntityID(); + OBSID.setSite(1); // 0 is apparently not a valid site number, per the spec + OBSID.setApplication(1); + OBSID.setEntity(3); //change for each person I think??? - JMF + EntityType entityType = TGTespdu.getEntityType(); + // + //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 + // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 + // + entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 + entityType.setCountry(222); // USA TGT = 222 (Russia), OBS = 225 + entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 + entityType.setCategory((short) 1); // FDC TGT = 1, Tank OBS=40 OP + entityType.setSubcategory((short) 2); // M1068 TGT = 2, T72 tank NONE FOR OP + + Vector3Double location = new Vector3Double(); + location.setX(150.0); //TGT = 150 OBS = 75 + location.setY(150.0); //TGT = 150 OBS = 75 + location.setZ(20.0); //TGT = 20 OBS = 50 + TGTespdu.setEntityLocation(location); + int timestamp = disTime.getDisAbsoluteTimestamp(); + TGTespdu.setTimestamp(timestamp); + sender.run(TGTespdu); //sends inital here I am and who I am + + //other player to look out for: + EntityID FDCEntityID = new EntityID(); + FDCEntityID.setEntity(1); + FDCEntityID.setApplication(1); + FDCEntityID.setSite(1); + + EntityID OBSEntityID = new EntityID(); + OBSEntityID.setEntity(2); + OBSEntityID.setApplication(1); + OBSEntityID.setSite(1); + + /* BELOW IS THE RECIEVE CODE // + // // + // // + */ // + PduFactory factory; + MulticastSocket socket = null; + InetAddress address = null; + DatagramPacket packet; + short currentPduType; //will use the curentPduType as the check for sending other packets. + + try { + // TODO: Change the line below to make sense for each class + System.out.println("Russian T72 out on the prowl...\n\n"); + socket = new MulticastSocket(MULTICAST_PORT); + address = InetAddress.getByName(MULTICAST_GROUP); + socket.joinGroup(address); + + factory = new PduFactory(); + + while (true) // Loop infinitely, receiving datagrams + { + byte buffer[] = new byte[1500]; // typical MTU size + + packet = new DatagramPacket(buffer, buffer.length); // reset + + socket.receive(packet); + // + //TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE. + // + + String marking2 = new String(); + Pdu pdu = factory.createPdu(packet.getData()); + currentPduType = pdu.getPduType(); + if (currentPduType == 14) //stop/freeze PDU + { + System.out.println("recieved Stop/Freeze packet..."); + return; + } +// pdu.setExerciseID((short)5); + if (pdu != null) { + if (sentBufferList.contains(pdu.getTimestamp())) { + pdu = null; + } + if (pdu != null) { + + String currentPduTypeName = pdu.getClass().getName(); + if (currentPduType == 1) { + EntityStatePdu pdu2 = (EntityStatePdu) pdu; + marking2 = pdu2.getMarking().getCharactersString(); + } +//Keep adding any if statements as needed for the class you are building. + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU: "); + message.append("pduType "); + if (currentPduType < 10) { + message.append(" "); + } + message.append(currentPduType).append(" ").append(currentPduTypeName); + message.append(" "); + message.append(marking2); + System.out.println(message.toString()); + //Reference for PDU Types: + // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm + // + + + if (currentPduType == 2) //FirePDU + { + DetonationPdu det = new DetonationPdu(); + det.setExerciseID((short) 1); + det.setDetonationResult((short)1); + timestamp = disTime.getDisAbsoluteTimestamp(); + det.setTimestamp(timestamp); + sender.run(det); + } + + } else { + System.out.println("received packet but pdu is null and originated from Target. Still doing sketchy Russian things..."); + } + } + } + } catch (IOException e) { + System.out.println("Problem with Target.PduReceiver, see exception trace:"); + System.out.println(e); + } finally { + System.out.println("Target.PduReceiver complete. - T-72 DESTROYED!"); + } + + } + +} diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java index 8f5f185debed2fa1db5ce0369cc0854d19fa3cd7..7e09d371760f9be6ae40c2740c011b45a4544378 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java @@ -33,12 +33,18 @@ import java.util.ArrayList; * * @author garrettloeffelman */ -public class LoeffelmanSeversonDISImageReceiver { - - public static final int MULTICAST_PORT = 3000; +public class LoeffelmanSeversonDISImageReceiver +{ + /** socket parameter of interest */ + public static final int MULTICAST_PORT = 3000; + /** socket parameter of interest */ public static final String MULTICAST_GROUP = "239.1.2.15"; - public static final boolean USE_FAST_ESPDU = false; + static final boolean USE_FAST_ESPDU = false; + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String args[]) { Image image = null; diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java index 33b356220d55d5b7cabc68e4e55a16765c69b204..17d2d9bac2728c648de3c89a2b71fd7b27a32225 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java @@ -247,6 +247,10 @@ public class LoeffelmanSeversonDISImageSender { } } + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String args[]) { if (args.length == 2) { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/originals/LoeffelmanSeversonDISImageReceiver.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/originals/LoeffelmanSeversonDISImageReceiver.java index 7b3e3b48c3021aeeab202988603b72092c6c187a..e4caa15672847ed7026789cef8707221594aed57 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/originals/LoeffelmanSeversonDISImageReceiver.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/originals/LoeffelmanSeversonDISImageReceiver.java @@ -33,12 +33,19 @@ import java.util.ArrayList; * * @author garrettloeffelman */ -public class LoeffelmanSeversonDISImageReceiver { - - public static final int MULTICAST_PORT = 3000; +public class LoeffelmanSeversonDISImageReceiver +{ + /** socket parameter of interest */ + public static final int MULTICAST_PORT = 3000; + /** socket parameter of interest */ public static final String MULTICAST_GROUP = "239.1.2.15"; - public static final boolean USE_FAST_ESPDU = false; + /** socket parameter of interest */ + static final boolean USE_FAST_ESPDU = false; + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String args[]) { Image image = null; diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/originals/LoeffelmanSeversonDISImageSender.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/originals/LoeffelmanSeversonDISImageSender.java index 8aa71f254dd4f8be336578a5704fbbed5bbbe291..854d0f3929f7c8c564c869ee49bf35aa7e7e2786 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/originals/LoeffelmanSeversonDISImageSender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson/originals/LoeffelmanSeversonDISImageSender.java @@ -237,6 +237,10 @@ public class LoeffelmanSeversonDISImageSender { } } + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String args[]) { if (args.length == 2) { diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Boron/BoronClient.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Boron/BoronClient.java index 996844672b571a90dcf02b8f8e6c511478c1de07..594c11da1e33e194b049efd577d3f223e0b3104b 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Boron/BoronClient.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Boron/BoronClient.java @@ -14,6 +14,7 @@ import java.net.*; public class BoronClient { // IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; /** diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/SirTobiClient.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/SirTobiClient.java index 89db3b497d11f566ca7c9345ac00629729a7cff8..56a70712a26361c96d10b8315b2ded6f97efbab4 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/SirTobiClient.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/SirTobiClient.java @@ -16,6 +16,7 @@ import java.net.*; public class SirTobiClient { // IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; /** diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/FetterolfHomework2Client.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/FetterolfHomework2Client.java index 8667124650d52243ad5bd2674440aee79e461ea2..4740ba28a937544b7aaba8bc96422aa40d25ea3c 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/FetterolfHomework2Client.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/FetterolfHomework2Client.java @@ -1,6 +1,5 @@ package MV3500Cohort2019JulySeptember.homework2.Fetterolf; -import MV3500Cohort2019JulySeptember.homework2.*; import java.io.*; import java.net.*; diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/FetterolfHomework2Server.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/FetterolfHomework2Server.java index 68b6c9df0d008c805068277e0123f0e7706d3184..4380af80a4f2cee464b7d2427cfa2fc17e08e647 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/FetterolfHomework2Server.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/FetterolfHomework2Server.java @@ -1,6 +1,5 @@ package MV3500Cohort2019JulySeptember.homework2.Fetterolf; -import MV3500Cohort2019JulySeptember.homework2.*; import java.io.*; import java.net.*; import java.util.Scanner; diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Knobeloch/Knobeloch_TCPIP_Server.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Knobeloch/Knobeloch_TCPIP_Server.java index ddb8936bfe9de6d37c3d931586e07cc05b217c4e..82ef93d0102906081aacaa5aba42acd30538a8f6 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Knobeloch/Knobeloch_TCPIP_Server.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Knobeloch/Knobeloch_TCPIP_Server.java @@ -24,6 +24,11 @@ import java.net.*; */ public class Knobeloch_TCPIP_Server { + /** + * Program invocation, execution starts here + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels program + */ public static void main(String[] args) throws InterruptedException { try { diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannClient.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannClient.java index dad6563446742c8e1d3ca3f38c174c910eaa246f..230387392f2337bc5240bacbc979e3d4e1d11187 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannClient.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannClient.java @@ -1,79 +1,84 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package MV3500Cohort2019JulySeptember.homework2.McCann; - -import MV3500Cohort2019JulySeptember.homework2.*; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.Socket; -import java.io.*; -import java.net.*; -import static javax.swing.Spring.constant; - -/** - * - * @author ljmm1 - */ -public class McCannClient { - - // IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 - public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; - - public static void main(String[] args) { - - // Local vars/fields - Socket socket; - InputStream is; - InputStreamReader isr; - BufferedReader br; - String serverMessage; - - try { - while (true) { - - - // We request an IP to connect to ("localhost") and - // port number at that IP (2317). This establishes - // a connection to that IP in the form of a Socket - // object; the server uses a ServerSocket to wait for - // connections. - socket = new Socket(LOCALHOST, 2317); // locohost? - - // Now hook everything up (i.e. set up the streams), Java style: - is = socket.getInputStream(); - isr = new InputStreamReader(is); - br = new BufferedReader(isr); - - // Read a single line written by the server. We'd - // do things a bit differently if there were many lines to be read - // from the server instead of one only. - serverMessage = br.readLine(); - System.out.println("=================================================="); - // System.out.println("Now we're talking!"); - - System.out.println(serverMessage); - System.out.println("My name is Sir Launcelot of Camelot"); - System.out.println("What is your quest?"); - // socket gets closed, either automatically/silently by this code (or possibly by the server) - - } // end while(true) - } catch (IOException e) { - System.err.println("Problem with TcpExample3ServerClient networking:"); // describe what is happening - System.err.println("Error: " + e); - - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) { - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } finally { - - // program exit: tell somebody about that - System.out.println("\nclient exit"); - } - } -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package MV3500Cohort2019JulySeptember.homework2.McCann; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.Socket; +import java.io.*; +import java.net.*; +import static javax.swing.Spring.constant; + +/** + * + * @author ljmm1 + */ +public class McCannClient +{ + + /** socket parameter of interest */ // IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + /** socket parameter of interest */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) { + + // Local vars/fields + Socket socket; + InputStream is; + InputStreamReader isr; + BufferedReader br; + String serverMessage; + + try { + while (true) { + + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2317); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("=================================================="); + // System.out.println("Now we're talking!"); + + System.out.println(serverMessage); + System.out.println("My name is Sir Launcelot of Camelot"); + System.out.println("What is your quest?"); + // socket gets closed, either automatically/silently by this code (or possibly by the server) + + } // end while(true) + } catch (IOException e) { + System.err.println("Problem with TcpExample3ServerClient networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } finally { + + // program exit: tell somebody about that + System.out.println("\nclient exit"); + } + } +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannServer.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannServer.java index 208095fa2edf1790d004ba90acd62e1917ed75b3..401089d99c26ea1ba4d0d410cc164c038345289b 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannServer.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannServer.java @@ -1,83 +1,87 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package MV3500Cohort2019JulySeptember.homework2.McCann; - -import MV3500Cohort2019JulySeptember.homework2.*; -import java.io.*; -import java.net.*; -import java.util.Scanner; - -/** - * - * @author ljmm1 - */ -public class McCannServer { - - public static void main(String[] args) { - try { - - // ServerSocket waits for a connection from a client. - // Notice that it is outside the loop; ServerSocket - // needs to be made only once. - System.out.println("McCannServer has started..."); // it helps debugging to put this on console first - //System.out.println("What is your name?"); - ServerSocket serverSocket = new ServerSocket(2317); - OutputStream os; - PrintStream ps; - InetAddress localAddress, remoteAddress; - int localPort, remotePort; - - // Server is up and waiting (i.e. "blocked" or paused) - // Loop, infinitely, waiting for client connections. - // Stop the program somewhere else. - while (true) { - - // block until connected to a client - try (Socket clientConnection = serverSocket.accept()) { - - // Now hook everything up (i.e. set up the streams), Java style: - os = clientConnection.getOutputStream(); - ps = new PrintStream(os); - Scanner keyboard = new Scanner(System.in); - ps.println("What is your name?"); // this gets sent back to client! - //tried to add an input but couldn't get it to work - //String message = keyboard.nextLine(); - // ps.println(message); - - // Print some information locally about the Socket connection. - // This includes the port and IP numbers on both sides (the socket pair). - localAddress = clientConnection.getLocalAddress(); - remoteAddress = clientConnection.getInetAddress(); - localPort = clientConnection.getLocalPort(); - remotePort = clientConnection.getPort(); - - // My socket pair connection looks like this, to localhost: - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) - - // Why is the first IP/port the same, while the second set has different ports? - System.out.println("TcpExample3Server socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " - + remoteAddress.toString() + ", " + remotePort + " ))"); - - // Notice the use of flush() and try w/ resources. Without - // the try w/ resources the Socket object may stay open for - // a while after the client has stopped needing this - // connection. try w/ resources explicitly ends the connection. - ps.flush(); - // like it or not, you're outta here! - } - } - } catch (IOException e) { - System.err.println("Problem with TcpExample3Server networking: " + e); - - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) { - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } - } - -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package MV3500Cohort2019JulySeptember.homework2.McCann; + +import java.io.*; +import java.net.*; +import java.util.Scanner; + +/** + * + * @author ljmm1 + */ +public class McCannServer { + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) + { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println("McCannServer has started..."); // it helps debugging to put this on console first + //System.out.println("What is your name?"); + ServerSocket serverSocket = new ServerSocket(2317); + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try (Socket clientConnection = serverSocket.accept()) { + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnection.getOutputStream(); + ps = new PrintStream(os); + Scanner keyboard = new Scanner(System.in); + ps.println("What is your name?"); // this gets sent back to client! + //tried to add an input but couldn't get it to work + //String message = keyboard.nextLine(); + // ps.println(message); + + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnection.getLocalAddress(); + remoteAddress = clientConnection.getInetAddress(); + localPort = clientConnection.getLocalPort(); + remotePort = clientConnection.getPort(); + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + + // Why is the first IP/port the same, while the second set has different ports? + System.out.println("TcpExample3Server socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + + remoteAddress.toString() + ", " + remotePort + " ))"); + + // Notice the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with TcpExample3Server networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } + +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.java index 1e5ed3ef2c0bc419a968d7da14b2af6e0b17decf..be05e6258a88660af080eb02a55edf05b4d672ab 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.java @@ -9,8 +9,12 @@ import java.net.*; * * @author Schutt */ -public class SchuttClient { - +public class SchuttClient +{ + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { // Local vars/fields diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServerDispatcher.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServerDispatcher.java index e23e63df7a02a665e0baebd7c043b85a6e64ab61..cd2ffce0fb43adc7013e8919ecf424eb6e4bfcff 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServerDispatcher.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServerDispatcher.java @@ -9,8 +9,13 @@ import java.net.*; * * @author Schutt */ -public class SchuttServerDispatcher { +public class SchuttServerDispatcher +{ + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) // execution starts here { try{ diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduReceiver.java index d0fb9650e901642d4bcc5ec3f352658ab7c46110..62ad868fb850fb6ca3eebcb5925e103231b3af6c 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduReceiver.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduReceiver.java @@ -18,9 +18,11 @@ import edu.nps.moves.dis7.utilities.*; public class BoronPduReceiver { - public static final int DEFAULT_MULTICAST_PORT = BoronPduSender.DEFAULT_MULTICAST_PORT; - public static final String DEFAULT_MULTICAST_ADDRESS = BoronPduSender.DEFAULT_MULTICAST_ADDRESS; - public static final boolean USE_FAST_ESPDU = false; + /** socket parameter of interest */ + public static final int DEFAULT_MULTICAST_PORT = BoronPduSender.DEFAULT_MULTICAST_PORT; + /** socket parameter of interest */ + public static final String DEFAULT_MULTICAST_ADDRESS = BoronPduSender.DEFAULT_MULTICAST_ADDRESS; + static final boolean USE_FAST_ESPDU = false; /** * Program invocation, execution starts here diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduSender.java index e716b530dc4b84fc1908862e7fb3b5de489fc7c7..2830627ffeaf652fadb37b8df1ae833a10a1cc1f 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduSender.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduSender.java @@ -26,7 +26,8 @@ public class BoronPduSender private int port; InetAddress multicastAddress; - public BoronPduSender(int port, String multicast) { + public BoronPduSender(int port, String multicast) + { try { this.port = port; diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/BrennenstuhlEspduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/BrennenstuhlEspduSender.java index 3523e189825bbc6f4c533d99e6ac093a612a5863..231aa4017787551b7ef2fb62118593f3a9330f5d 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/BrennenstuhlEspduSender.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/BrennenstuhlEspduSender.java @@ -19,7 +19,7 @@ import edu.nps.moves.dis7.enumerations.PlatformDomain; */ public class BrennenstuhlEspduSender { - public static final int NUMBER_TO_SEND = 5; // 5000 + static final int NUMBER_TO_SEND = 5; // 5000 /** diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/Version2/AllPduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/Version2/AllPduReceiver.java index ec33bba46cdb4ab7e1f515a338c1566ce197f0d3..96f1df7633641b8892dcd14628064e2966b4afd5 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/Version2/AllPduReceiver.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/Version2/AllPduReceiver.java @@ -10,9 +10,11 @@ import java.util.ArrayList; public class AllPduReceiver { - public static final int DEFAULT_MULTICAST_PORT = AllPduSender.DEFAULT_MULTICAST_PORT; - public static final String DEFAULT_MULTICAST_ADDRESS = AllPduSender.DEFAULT_MULTICAST_ADDRESS; - public static final boolean USE_FAST_ESPDU = false; + /** socket parameter of interest */ + public static final int DEFAULT_MULTICAST_PORT = AllPduSender.DEFAULT_MULTICAST_PORT; + /** socket parameter of interest */ + public static final String DEFAULT_MULTICAST_ADDRESS = AllPduSender.DEFAULT_MULTICAST_ADDRESS; + static final boolean USE_FAST_ESPDU = false; public static void main(String args[]) { diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduReceiver.java index 3de8c19b07a59e3b770e69a4fdb6ac86b3a398b9..f5f2f7c5dcb93c047e521204f631b2f522136c01 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduReceiver.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduReceiver.java @@ -11,8 +11,12 @@ public class Knobeloch_PduReceiver { public static final int DEFAULT_MULTICAST_PORT = Knobeloch_PduSender.DEFAULT_MULTICAST_PORT; public static final String DEFAULT_MULTICAST_ADDRESS = Knobeloch_PduSender.DEFAULT_MULTICAST_ADDRESS; - public static final boolean USE_FAST_ESPDU = false; + static final boolean USE_FAST_ESPDU = false; + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String args[]) { PduFactory factory; diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduSender.java index ca64e3c2c1b6b7a8254bb4d9f807436e9087a5cc..626a30555b7f2305f16fbb92864e3e15608e0daa 100755 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduSender.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduSender.java @@ -91,6 +91,10 @@ public class Knobeloch_PduSender } } + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String args[]) { if (args.length == 2) diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/McCann/McCannPduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/McCann/McCannPduReceiver.java index 2bf8e0c912a3bda54180c1173189de5538ecf46a..a64e729f78641da1b29c10f2beedd08b0bb4a156 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/McCann/McCannPduReceiver.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/McCann/McCannPduReceiver.java @@ -10,10 +10,16 @@ import java.util.ArrayList; public class McCannPduReceiver { - public static final int DEFAULT_MULTICAST_PORT = McCannPduSender.DEFAULT_MULTICAST_PORT; - public static final String DEFAULT_MULTICAST_ADDRESS = McCannPduSender.DEFAULT_MULTICAST_ADDRESS; - public static final boolean USE_FAST_ESPDU = false; + /** socket parameter of interest */ + public static final int DEFAULT_MULTICAST_PORT = McCannPduSender.DEFAULT_MULTICAST_PORT; + /** socket parameter of interest */ + public static final String DEFAULT_MULTICAST_ADDRESS = McCannPduSender.DEFAULT_MULTICAST_ADDRESS; + static final boolean USE_FAST_ESPDU = false; + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String args[]) { PduFactory factory; diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/McCann/McCannPduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/McCann/McCannPduSender.java index f977877f8571a205883ac78253b40791b9e0e34f..3ad2da6423ecc89a7821db0fb56ce2b08a2aa805 100755 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/McCann/McCannPduSender.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/McCann/McCannPduSender.java @@ -465,6 +465,10 @@ public class McCannPduSender } } + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String args[]) { if (args.length == 2) diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttESPDUSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttESPDUSender.java index c84558a28f586f269d91fbf8783899430091a92d..c5eea7be576d8786e53a4d03204a314aa2032654 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttESPDUSender.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttESPDUSender.java @@ -26,7 +26,7 @@ import java.nio.ByteBuffer; */ public class SchuttESPDUSender { - public static final int NUMBER_TO_SEND = 5; // 5000 + static final int NUMBER_TO_SEND = 5; // 5000 /** * Default multicast group address we send on. diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttEspduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttEspduReceiver.java index ef2c11e4e87e74722d0950bcfe3746b772178465..c866a1fb5c8c700a439354f4635e6762cf1228cf 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttEspduReceiver.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttEspduReceiver.java @@ -28,6 +28,10 @@ public class SchuttEspduReceiver /** Default multicast port used, matches Wireshark DIS capture default */ public static final int DEFAULT_MULTICAST_PORT = SchuttESPDUSender.DEFAULT_MULTICAST_PORT; + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String args[]) { System.out.println("DisExamplesOpenDis7.EspduReceiver started..."); diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttPDUSaverListener.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttPDUSaverListener.java index b4e9018c36866a4c67a4322d7ab2cdd28157954a..1260918c3c8d57e4e229907a6610742c11b72ebc 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttPDUSaverListener.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Schutt/SchuttPDUSaverListener.java @@ -27,6 +27,10 @@ public class SchuttPDUSaverListener PAUSED; } + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { String outDir = DEFAULT_OUTPUTDIR; diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Yurkovich/Yurk_EspduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Yurkovich/Yurk_EspduSender.java index 257f567ba59e4d9420577aa1ac8927592862d479..68597af2f7015773f1fd9d1e6000f7f50298c113 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Yurkovich/Yurk_EspduSender.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Yurkovich/Yurk_EspduSender.java @@ -16,7 +16,7 @@ import edu.nps.moves.dis7.utilities.*; */ public class Yurk_EspduSender { - public static final int NUMBER_TO_SEND = 5; // 5000 + static final int NUMBER_TO_SEND = 5; // 5000 /** * Default multicast group address we send on. diff --git a/assignments/src/MV3500Cohort2019JulySeptember/projects/BrennenstuhlKnobelochMcCann/BRE_KNO_MCC_PC2_PC1_MCAST_PduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/projects/BrennenstuhlKnobelochMcCann/BRE_KNO_MCC_PC2_PC1_MCAST_PduReceiver.java index d9a767d946b08a3ed47c2cc6bbd21731f5f1bd1b..04f00cadb54cade62a15cae86db458e06fc5e0bc 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/projects/BrennenstuhlKnobelochMcCann/BRE_KNO_MCC_PC2_PC1_MCAST_PduReceiver.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/projects/BrennenstuhlKnobelochMcCann/BRE_KNO_MCC_PC2_PC1_MCAST_PduReceiver.java @@ -17,7 +17,7 @@ import java.util.logging.Logger; public class BRE_KNO_MCC_PC2_PC1_MCAST_PduReceiver extends Thread { - public static final boolean USE_FAST_ESPDU = false; + static final boolean USE_FAST_ESPDU = false; static List<Integer> savedMCASTMessages = new ArrayList(); static List<Pdu> mcastMessagesToSend = new ArrayList(); static Mutex mutex = new Mutex(); diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework2/Cannon/CannonClient.java b/assignments/src/MV3500Cohort2020JulySeptember/homework2/Cannon/CannonClient.java index af3cddb99ab61aa33b25aed577622ca09a6e9a99..6885993f3755a12a0e79a376f29904ea988eb856 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework2/Cannon/CannonClient.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework2/Cannon/CannonClient.java @@ -23,6 +23,7 @@ import java.net.Socket; public class CannonClient { // IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; /** diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework2/Mahan/Mahan_Client.java b/assignments/src/MV3500Cohort2020JulySeptember/homework2/Mahan/Mahan_Client.java index a3bc4bc62668dd67bd48c7cd79a86b97979e4a0a..429fc7b3fdc8aae8a407fe2e5b9da3cb0f2deefb 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework2/Mahan/Mahan_Client.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework2/Mahan/Mahan_Client.java @@ -6,11 +6,16 @@ import java.net.*; * * @author Bill */ -public class Mahan_Client { - +public class Mahan_Client +{ // IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { // Local vars/fields diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework2/Mahan/Mahan_Server.java b/assignments/src/MV3500Cohort2020JulySeptember/homework2/Mahan/Mahan_Server.java index 7e8ef6460bda2cb538461e6dc6d4cf61b5d6482c..dcc26646da7a169959570d4fd03f8e8dbade8816 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework2/Mahan/Mahan_Server.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework2/Mahan/Mahan_Server.java @@ -7,8 +7,12 @@ import java.net.*; * * @author Bill */ -public class Mahan_Server { - +public class Mahan_Server +{ + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { try { diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Britt/UdpReceiver.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Britt/UdpReceiver.java index 869bc444d15ade6a546dba5e999f01eb9782771c..e87809cd11168a1121187c3090356ab87c5e1bd5 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Britt/UdpReceiver.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Britt/UdpReceiver.java @@ -18,7 +18,9 @@ import java.net.*; public class UdpReceiver { // public static final int SENDING_PORT = 1414; // port used by UdpSender, unneeded here + /** socket parameter of interest */ public static final int RECEIVING_PORT = 1415; + /** socket parameter of interest */ public static final String DESINATION_HOST = "localhost"; /** diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Britt/UdpSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Britt/UdpSender.java index 63480cde717525156fc2569671f73672ded45e26..a98f5e4ca49bf75a3319ed8c7634ff729fbf23dd 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Britt/UdpSender.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Britt/UdpSender.java @@ -19,12 +19,15 @@ import java.net.*; */ public class UdpSender { - public static final String MY_NAME = System.getProperty("user.name"); // guru incantation 8) + 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 parameter of interest */ public static final int RECEIVING_PORT = 1415; + /** socket parameter of interest */ public static final int TOTAL_PACKETS_TO_SEND = 100; // here is what we need for lab comms + /** socket parameter of interest */ public static final String DESTINATION_HOST = "10.1.105.16"; // localhost 127.0.0.1 or argon 10.1.105.1 or 10.1.105.1 or whatever @SuppressWarnings("SleepWhileInLoop") diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonUdpSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonUdpSender.java index d43debea1543fa6f93e4bac4a70475e3c85a3cde..201edd748840cbb494b00252f95257513aeae326 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonUdpSender.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonUdpSender.java @@ -26,6 +26,7 @@ public class CannonUdpSender private static final int TOTAL_PACKETS_TO_SEND = 100; // here is what we need for lab comms + /** socket parameter of interest */ public static final String DESTINATION_HOST = "10.1.105.7"; // localhost 127.0.0.1 or argon 10.1.105.1 or 10.1.105.1 or whatever /** diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpReceiver.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpReceiver.java index af090a23bd74a8a2b1e1a08c17ae134af1b6606a..39f689c8d20715c2d9e4ca8bba95e9b33b074ad8 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpReceiver.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpReceiver.java @@ -10,7 +10,9 @@ import java.net.*; public class MahanUdpReceiver { // public static final int SENDING_PORT = 1414; // port used by UdpSender, unneeded here + /** socket parameter of interest */ public static final int RECEIVING_PORT = 1415; + /** socket parameter of interest */ public static final String DESINATION_HOST = "10.1.105.12"; /** diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpSender.java index 199cbd5217bd2e9ce943a7df983686dc3ed3a474..633ac03b6917f8d5d7d295a8ac0fde0f867e5b69 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpSender.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpSender.java @@ -10,14 +10,21 @@ import java.net.*; public class MahanUdpSender { // System properties: https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html - public static final String MY_NAME = System.getProperty("user.name"); // guru incantation 8) + 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 parameter of interest */ public static final int RECEIVING_PORT = 1415; + /** socket parameter of interest */ public static final int TOTAL_PACKETS_TO_SEND = 100; // here is what we need for lab comms + /** socket parameter of interest */ public static final String DESTINATION_HOST = "10.1.105.12"; // localhost 127.0.0.1 or argon 10.1.105.1 or 10.1.105.1 or whatever + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ @SuppressWarnings("SleepWhileInLoop") public static void main(String[] args) throws IOException { diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/TCPNumberSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/TCPNumberSender.java index 5f00e22ff84f4a7810377948dba618ae9fbc746e..0301696245af21a2b50b18f3e5d64736a5023a14 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/TCPNumberSender.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/TCPNumberSender.java @@ -17,18 +17,21 @@ import java.net.Socket; public class TCPNumberSender { // Change this to the IP address of the TCP server 10.1.105.9 (127.0.0.1 just for testing) + /** socket parameter of interest */ public static final String TCP_ARGON_SERVER_IP = "127.0.0.1"; // Change this to the port where the TCP server is listening + /** socket parameter of interest */ public static final int TCP_ARGON_SERVER_PORT = 2317; // Where the result should be posted (port) + /** socket parameter of interest */ public static final int UDP_ARGON_RECEIVING_PORT = 1415; - public static final int NUMBER1 = 16; - public static final int NUMBER2 = 2; - public static final String CALCULATION_METHOD = "-"; + static final int NUMBER1 = 16; + static final int NUMBER2 = 2; + static final String CALCULATION_METHOD = "-"; // how many times should the number being sent - public static final int REPETITION = 1; + private static final int REPETITION = 1; private static int counter = 0; public static void main(String[] args) throws InterruptedException { diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/UDPResultReceiver.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/UDPResultReceiver.java index 8dc85b0427ad8f360a8577944cc97c55cea5bf27..939f63f4ef32252f4d7a44429938f621c844406e 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/UDPResultReceiver.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/UDPResultReceiver.java @@ -16,6 +16,7 @@ import java.net.DatagramSocket; */ public class UDPResultReceiver { + /** socket parameter of interest */ public static final int RECEIVING_PORT = 1415; /** diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/TCPNumberReceiverUDPResultSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/TCPNumberReceiverUDPResultSender.java index 30eeb323c6b5b7fa12dbd6abd8fbf8dc535db36a..016bd924e2332e1d73df4e032b49ab20c86cd3f4 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/TCPNumberReceiverUDPResultSender.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/TCPNumberReceiverUDPResultSender.java @@ -22,6 +22,7 @@ import java.net.Socket; public class TCPNumberReceiverUDPResultSender { // Change this to the port where the TCP server is listening + /** socket parameter of interest */ public static final int TCP_ARGON_SERVER_PORT = 2317; /** diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/test/PDUReciever.java b/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/test/PDUReceiver.java similarity index 97% rename from assignments/src/MV3500Cohort2020JulySeptember/homework4/White/test/PDUReciever.java rename to assignments/src/MV3500Cohort2020JulySeptember/homework4/White/test/PDUReceiver.java index cb0b4929c443ff7614054a9f290669805a36c0c8..c029215bc3a66369422c4b51acfbce95a7f0a856 100755 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/test/PDUReciever.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/test/PDUReceiver.java @@ -1,144 +1,146 @@ -package MV3500Cohort2020JulySeptember.homework4.White.test; - -import MV3500Cohort2020JulySeptember.homework4.White.working.*; -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis7.pdus.*; -import edu.nps.moves.dis7.utilities.*; - -/** - * Receives PDUs from GermanyEspduReceiverEspduVPNSender in IEEE DIS format. - * - * @version 09/05/2020 - * @author Bernd/Stefan - * @version 0.1 - */ -public class PDUReciever { - - /** - * Max size of a PDU in binary format that we can receive. This is actually - * somewhat outdated--PDUs can be larger--but this is a reasonable starting - * point. - */ - public static final int MAX_PDU_SIZE = 8192; - - /** - * Default port used, matches Wireshark DIS capture default - */ - public static final int DEFAULT_PORT = 2317; - public static final int SECOND_PORT = 3000; - public static final int THIRD_PORT = 2318; - - - /** - * Output prefix to identify this class - */ - private final static String TRACE_PREFIX = "[" + PDUReciever.class.getName() + "] "; - - public static void main(String args[]) { - System.out.println(TRACE_PREFIX + "started..."); - - MulticastSocket socket1; - MulticastSocket socket2; - MulticastSocket socket3; - DatagramPacket packet; - DatagramPacket packet2; - DatagramPacket packet3; - PduFactory pduFactory = new PduFactory(); - ArrayList<EntityID> knownEntities = new ArrayList<EntityID>(); - int pduCount = 0; - - try { - // Specify the socket to receive data - socket1 = new MulticastSocket(DEFAULT_PORT); - socket2 = new MulticastSocket(SECOND_PORT); - socket3 = new MulticastSocket(THIRD_PORT); - - System.out.println(TRACE_PREFIX + "listening for PDU packets on port " + DEFAULT_PORT );//+ " " + SECOND_PORT + " " + THIRD_PORT); - System.out.println("===================================================="); - - while (true) // Loop infinitely, receiving datagrams - { - byte buffer[] = new byte[MAX_PDU_SIZE]; - packet = new DatagramPacket(buffer, buffer.length); - - socket1.receive(packet); - - - - List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData(), packet.getLength()); - if (pduBundle.size() > 1) { // should be 1 for this project - System.out.println("Bundle size is " + pduBundle.size()); - } - - // end iterator loop through PDU bundle - for (Pdu aPdu : pduBundle) { - pduCount++; - String receiptMessage = String.format("%3s", pduCount) // right justify, 3 characters - + ". received PDU type " + aPdu.getPduType().getValue() + "=" + aPdu.getPduType().name() + " " + aPdu.getClass().getName() + " from " + packet.getAddress(); - if (aPdu instanceof EntityStatePdu) { - System.out.println(receiptMessage); - EntityID entityID = ((EntityStatePdu) aPdu).getEntityID(); - Vector3Double position = ((EntityStatePdu) aPdu).getEntityLocation(); - System.out.println(" entityID triplet: [" + entityID.getSiteID() + ", " + entityID.getApplicationID() + ", " + entityID.getEntityID() + "] "); - if (!knownEntities.contains(entityID)){ - knownEntities.add(entityID); - EntityType entityType = ((EntityStatePdu) aPdu).getEntityType(); - System.out.println(" New Entity: " +entityType.getEntityKind() + " "+ entityType.getDomain() + " "+ entityType.getCountry() + " "+ entityType.getCategory() + " "+ entityType.getSubCategory() + " "+ entityType.getSpecific() ); - } - System.out.println(" Location in DIS coordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]"); - - } - else if (aPdu instanceof FirePdu){ - System.out.println(receiptMessage); - EntityID firingEntityID = ((FirePdu) aPdu).getFiringEntityID(); - EntityID targetEntityID = ((FirePdu) aPdu).getTargetEntityID(); - MunitionDescriptor munitionDescriptor = ((FirePdu) aPdu).getDescriptor(); - System.out.println(" firingEntityID triplet: [" + firingEntityID.getSiteID() + ", " + firingEntityID.getApplicationID() + ", " + firingEntityID.getEntityID() + "] "); - System.out.println(" targetEntityID triplet: [" + targetEntityID.getSiteID() + ", " + targetEntityID.getApplicationID() + ", " + targetEntityID.getEntityID() + "] "); - System.out.println(" Munition Information: [" + munitionDescriptor.getMunitionType().getDomain() + "."+munitionDescriptor.getMunitionType().getCountry() + "." + munitionDescriptor.getMunitionType().getCategory() + "."+ munitionDescriptor.getMunitionType().getSubCategory() + "." + munitionDescriptor.getMunitionType().getSpecific() + "]"); - } - else if (aPdu instanceof CommentReliablePdu){ - System.out.println(receiptMessage); - ArrayList<VariableDatum> payloadList = (ArrayList)((CommentReliablePdu) aPdu).getVariableDatumRecords(); - if (!payloadList.isEmpty()) - System.out.print (" messages: "); - for (VariableDatum variableDatum : payloadList) - { - String nextComment = new String(variableDatum.getVariableDatumValue()); // convert byte[] to String - System.out.print (" \"" + nextComment + "\""); - System.out.println(); - }// - } - else if (aPdu instanceof ResupplyOfferPdu){ - System.out.println(receiptMessage); - EntityID receiverID = ((ResupplyOfferPdu) aPdu).getReceivingEntityID(); - EntityID supplierID = ((ResupplyOfferPdu) aPdu).getSupplyingEntityID(); - List<SupplyQuantity> supplyList = ((ResupplyOfferPdu) aPdu).getSupplies(); - System.out.println(" Resupply Offer from Entity [" + supplierID.getSiteID() + ", "+ supplierID.getApplicationID() + ", " + supplierID.getEntityID() + "] to resupply Entity ["+ receiverID.getSiteID() + ", "+ receiverID.getApplicationID() + ", " + receiverID.getEntityID() + "]" ); - for (int i = 0; i < supplyList.size(); i++){ - SupplyQuantity supplyQ = supplyList.get(i); - EntityType entityType = supplyQ.getSupplyType(); - float supplyQuantity = supplyQ.getQuantity(); - System.out.println(" Supplies Offered: [Quantity: " + supplyQuantity + ", Type: " +entityType.getEntityKind() + " "+ entityType.getDomain() + " "+ entityType.getCountry() + " "+ entityType.getCategory() + " "+ entityType.getSubCategory() + " "+ entityType.getSpecific() + " ]"); - - } - } - - //OTHER PDU TYPES - else { - System.out.println(receiptMessage); - } - } // end of bundle loop - - } // end of while loop - } // end try block // end try block // end try block // end try block - catch (IOException ioe) { - System.out.println(TRACE_PREFIX + "Problem with input/output, see exception trace:"); - System.out.println(ioe); - } - System.out.println(TRACE_PREFIX + "complete."); - } // end main -} // end class +package MV3500Cohort2020JulySeptember.homework4.White.test; + +import MV3500Cohort2020JulySeptember.homework4.White.working.*; +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis7.pdus.*; +import edu.nps.moves.dis7.utilities.*; + +/** + * Receives PDUs from GermanyEspduReceiverEspduVPNSender in IEEE DIS format. + * + * @version 09/05/2020 + * @author Bernd/Stefan + * @version 0.1 + */ +public class PDUReceiver { + + /** + * Max size of a PDU in binary format that we can receive. This is actually + * somewhat outdated--PDUs can be larger--but this is a reasonable starting + * point. + */ + public static final int MAX_PDU_SIZE = 8192; + + /** + * Default port used, matches Wireshark DIS capture default + */ + public static final int DEFAULT_PORT = 2317; + /** socket parameter of interest */ + public static final int SECOND_PORT = 3000; + /** socket parameter of interest */ + public static final int THIRD_PORT = 2318; + + + /** + * Output prefix to identify this class + */ + private final static String TRACE_PREFIX = "[" + PDUReceiver.class.getName() + "] "; + + public static void main(String args[]) { + System.out.println(TRACE_PREFIX + "started..."); + + MulticastSocket socket1; + MulticastSocket socket2; + MulticastSocket socket3; + DatagramPacket packet; + DatagramPacket packet2; + DatagramPacket packet3; + PduFactory pduFactory = new PduFactory(); + ArrayList<EntityID> knownEntities = new ArrayList<EntityID>(); + int pduCount = 0; + + try { + // Specify the socket to receive data + socket1 = new MulticastSocket(DEFAULT_PORT); + socket2 = new MulticastSocket(SECOND_PORT); + socket3 = new MulticastSocket(THIRD_PORT); + + System.out.println(TRACE_PREFIX + "listening for PDU packets on port " + DEFAULT_PORT );//+ " " + SECOND_PORT + " " + THIRD_PORT); + System.out.println("===================================================="); + + while (true) // Loop infinitely, receiving datagrams + { + byte buffer[] = new byte[MAX_PDU_SIZE]; + packet = new DatagramPacket(buffer, buffer.length); + + socket1.receive(packet); + + + + List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData(), packet.getLength()); + if (pduBundle.size() > 1) { // should be 1 for this project + System.out.println("Bundle size is " + pduBundle.size()); + } + + // end iterator loop through PDU bundle + for (Pdu aPdu : pduBundle) { + pduCount++; + String receiptMessage = String.format("%3s", pduCount) // right justify, 3 characters + + ". received PDU type " + aPdu.getPduType().getValue() + "=" + aPdu.getPduType().name() + " " + aPdu.getClass().getName() + " from " + packet.getAddress(); + if (aPdu instanceof EntityStatePdu) { + System.out.println(receiptMessage); + EntityID entityID = ((EntityStatePdu) aPdu).getEntityID(); + Vector3Double position = ((EntityStatePdu) aPdu).getEntityLocation(); + System.out.println(" entityID triplet: [" + entityID.getSiteID() + ", " + entityID.getApplicationID() + ", " + entityID.getEntityID() + "] "); + if (!knownEntities.contains(entityID)){ + knownEntities.add(entityID); + EntityType entityType = ((EntityStatePdu) aPdu).getEntityType(); + System.out.println(" New Entity: " +entityType.getEntityKind() + " "+ entityType.getDomain() + " "+ entityType.getCountry() + " "+ entityType.getCategory() + " "+ entityType.getSubCategory() + " "+ entityType.getSpecific() ); + } + System.out.println(" Location in DIS coordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]"); + + } + else if (aPdu instanceof FirePdu){ + System.out.println(receiptMessage); + EntityID firingEntityID = ((FirePdu) aPdu).getFiringEntityID(); + EntityID targetEntityID = ((FirePdu) aPdu).getTargetEntityID(); + MunitionDescriptor munitionDescriptor = ((FirePdu) aPdu).getDescriptor(); + System.out.println(" firingEntityID triplet: [" + firingEntityID.getSiteID() + ", " + firingEntityID.getApplicationID() + ", " + firingEntityID.getEntityID() + "] "); + System.out.println(" targetEntityID triplet: [" + targetEntityID.getSiteID() + ", " + targetEntityID.getApplicationID() + ", " + targetEntityID.getEntityID() + "] "); + System.out.println(" Munition Information: [" + munitionDescriptor.getMunitionType().getDomain() + "."+munitionDescriptor.getMunitionType().getCountry() + "." + munitionDescriptor.getMunitionType().getCategory() + "."+ munitionDescriptor.getMunitionType().getSubCategory() + "." + munitionDescriptor.getMunitionType().getSpecific() + "]"); + } + else if (aPdu instanceof CommentReliablePdu){ + System.out.println(receiptMessage); + ArrayList<VariableDatum> payloadList = (ArrayList)((CommentReliablePdu) aPdu).getVariableDatumRecords(); + if (!payloadList.isEmpty()) + System.out.print (" messages: "); + for (VariableDatum variableDatum : payloadList) + { + String nextComment = new String(variableDatum.getVariableDatumValue()); // convert byte[] to String + System.out.print (" \"" + nextComment + "\""); + System.out.println(); + }// + } + else if (aPdu instanceof ResupplyOfferPdu){ + System.out.println(receiptMessage); + EntityID receiverID = ((ResupplyOfferPdu) aPdu).getReceivingEntityID(); + EntityID supplierID = ((ResupplyOfferPdu) aPdu).getSupplyingEntityID(); + List<SupplyQuantity> supplyList = ((ResupplyOfferPdu) aPdu).getSupplies(); + System.out.println(" Resupply Offer from Entity [" + supplierID.getSiteID() + ", "+ supplierID.getApplicationID() + ", " + supplierID.getEntityID() + "] to resupply Entity ["+ receiverID.getSiteID() + ", "+ receiverID.getApplicationID() + ", " + receiverID.getEntityID() + "]" ); + for (int i = 0; i < supplyList.size(); i++){ + SupplyQuantity supplyQ = supplyList.get(i); + EntityType entityType = supplyQ.getSupplyType(); + float supplyQuantity = supplyQ.getQuantity(); + System.out.println(" Supplies Offered: [Quantity: " + supplyQuantity + ", Type: " +entityType.getEntityKind() + " "+ entityType.getDomain() + " "+ entityType.getCountry() + " "+ entityType.getCategory() + " "+ entityType.getSubCategory() + " "+ entityType.getSpecific() + " ]"); + + } + } + + //OTHER PDU TYPES + else { + System.out.println(receiptMessage); + } + } // end of bundle loop + + } // end of while loop + } // end try block // end try block // end try block // end try block + catch (IOException ioe) { + System.out.println(TRACE_PREFIX + "Problem with input/output, see exception trace:"); + System.out.println(ioe); + } + System.out.println(TRACE_PREFIX + "complete."); + } // end main +} // end class diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework1/LeckieTcpExample2.java b/assignments/src/MV3500Cohort2021JulySeptember/homework1/LeckieTcpExample2.java index 037e875c50c1d270f877119b837a3e2cda1ca00f..df128ef178a8e722c931db42395d7b2cbd4148d0 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework1/LeckieTcpExample2.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework1/LeckieTcpExample2.java @@ -1,103 +1,107 @@ -package pkg3500.leckie; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; - -/** - * Very slightly more complex than example1. The only thing this does - * differently is introduce a loop into the response, so you don't - * have to restart the program after one response. Also, it prints - * out the socket pair the server sees. Run the program via telnet - * several times and compare the socket pairs. - * - * <code>telnet localhost 2317</code> - * - * If you're sophisticated you can contact the instructor's computer - * while running this program. - * - * <code>telnet ipOfServersLaptop 2317</code> - * - * And have that machine display the socket pairs received. - * @author mcgredo - * @author brutzman - * @author leckie - */ -public class LeckieTcpExample2 -{ - public static void main(String[] args) - { - try - { - System.out.println("TcpExample2ConnectionCounting has started and is waiting for a connection."); - System.out.println(" help: https://savage.nps.edu/Savage/developers.html#telnet"); - System.out.println(" enter (nc localhost 2317) or (telnet localhost 2317)..." ); - - // ServerSocket waits for a connection from a client. - // Notice that it is outside the loop; ServerSocket needs to be made only once. - - int connectionCount = 0; // state variable - int totalEntrantCount = 31; // spoofed entrants - - ServerSocket serverSocket = new ServerSocket(2317); // server decides here what port to listen on. - // of interest: often client doesn't care what port it uses locally when connecting to that server port. - - // Loop, infinitely, waiting for client connections. - // Stop the program somewhere else. - while(true) - { - // blocks! then proceeds once a connection is "accept"ed - try (Socket clientConnection = serverSocket.accept()) { - connectionCount++; // got another one! - - OutputStream os = clientConnection.getOutputStream(); - PrintStream ps = new PrintStream(os); - - ps.println("This client response was written by server " + LeckieTcpExample2.class.getName()); // to remote client - System.out.println("This server response was written by server " + LeckieTcpExample2.class.getName()); // to server console - - ps.println("This is your lottery attempt number #" + connectionCount + ", you are aplicant number " + totalEntrantCount + " to try and win. Keep trying!"); - - totalEntrantCount = (totalEntrantCount + 79); - // Print some information locally about the Socket connection. - // This includes the port and IP numbers on both sides (the socket pair.) - - InetAddress localAddress = clientConnection.getLocalAddress(); - InetAddress remoteAddress = clientConnection.getInetAddress(); - - int localPort = clientConnection.getLocalPort(); - int remotePort = clientConnection.getPort(); // remember the prior question, why are 2 ports different? - - // My socket pair connection looks like this, to localhost: - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) note IPv6 - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) - // - // Why is first IP/port the same, while the second set has different ports? - - System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + - remoteAddress.toString() + ", " + remotePort + " ))"); - - System.out.println("got another connection, #" + connectionCount); // report progress - - // Notice the use of flush() and close(). Without - // the close() to Socket object may stay open for - // a while after the client has stopped needing this - // connection. Close() explicitly ends the connection. - ps.flush(); - } - } - } - catch(IOException e) - { - System.err.println("Problem with " + LeckieTcpExample2.class.getName() + " networking:"); // describe what is happening - System.err.println("Error: " + e); - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } - -} +package pkg3500.leckie; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * Very slightly more complex than example1. The only thing this does + * differently is introduce a loop into the response, so you don't + * have to restart the program after one response. Also, it prints + * out the socket pair the server sees. Run the program via telnet + * several times and compare the socket pairs. + * + * <code>telnet localhost 2317</code> + * + * If you're sophisticated you can contact the instructor's computer + * while running this program. + * + * <code>telnet ipOfServersLaptop 2317</code> + * + * And have that machine display the socket pairs received. + * @author mcgredo + * @author brutzman + * @author leckie + */ +public class LeckieTcpExample2 +{ + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) + { + try + { + System.out.println("TcpExample2ConnectionCounting has started and is waiting for a connection."); + System.out.println(" help: https://savage.nps.edu/Savage/developers.html#telnet"); + System.out.println(" enter (nc localhost 2317) or (telnet localhost 2317)..." ); + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket needs to be made only once. + + int connectionCount = 0; // state variable + int totalEntrantCount = 31; // spoofed entrants + + ServerSocket serverSocket = new ServerSocket(2317); // server decides here what port to listen on. + // of interest: often client doesn't care what port it uses locally when connecting to that server port. + + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while(true) + { + // blocks! then proceeds once a connection is "accept"ed + try (Socket clientConnection = serverSocket.accept()) { + connectionCount++; // got another one! + + OutputStream os = clientConnection.getOutputStream(); + PrintStream ps = new PrintStream(os); + + ps.println("This client response was written by server " + LeckieTcpExample2.class.getName()); // to remote client + System.out.println("This server response was written by server " + LeckieTcpExample2.class.getName()); // to server console + + ps.println("This is your lottery attempt number #" + connectionCount + ", you are aplicant number " + totalEntrantCount + " to try and win. Keep trying!"); + + totalEntrantCount = (totalEntrantCount + 79); + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair.) + + InetAddress localAddress = clientConnection.getLocalAddress(); + InetAddress remoteAddress = clientConnection.getInetAddress(); + + int localPort = clientConnection.getLocalPort(); + int remotePort = clientConnection.getPort(); // remember the prior question, why are 2 ports different? + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) note IPv6 + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + // + // Why is first IP/port the same, while the second set has different ports? + + System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + + remoteAddress.toString() + ", " + remotePort + " ))"); + + System.out.println("got another connection, #" + connectionCount); // report progress + + // Notice the use of flush() and close(). Without + // the close() to Socket object may stay open for + // a while after the client has stopped needing this + // connection. Close() explicitly ends the connection. + ps.flush(); + } + } + } + catch(IOException e) + { + System.err.println("Problem with " + LeckieTcpExample2.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework1/TcpExample2_Leckie_Mod_Hw1.java b/assignments/src/MV3500Cohort2021JulySeptember/homework1/TcpExample2_Leckie_Mod_Hw1.java index 6fed11d3d705393f355c5db404295fd373f5159c..12176c49203f1f884fbef2ff62ba85a3a49876f5 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework1/TcpExample2_Leckie_Mod_Hw1.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework1/TcpExample2_Leckie_Mod_Hw1.java @@ -1,103 +1,107 @@ -package pkg3500.leckie; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; - -/** - * Very slightly more complex than example1. The only thing this does - * differently is introduce a loop into the response, so you don't - * have to restart the program after one response. Also, it prints - * out the socket pair the server sees. Run the program via telnet - * several times and compare the socket pairs. - * - * <code>telnet localhost 2317</code> - * - * If you're sophisticated you can contact the instructor's computer - * while running this program. - * - * <code>telnet ipOfServersLaptop 2317</code> - * - * And have that machine display the socket pairs received. - * @author mcgredo - * @author brutzman - * @author leckie - */ -public class TcpExample2_Leckie_Mod_Hw1 -{ - public static void main(String[] args) - { - try - { - System.out.println("TcpExample2ConnectionCounting has started and is waiting for a connection."); - System.out.println(" help: https://savage.nps.edu/Savage/developers.html#telnet"); - System.out.println(" enter (nc localhost 2317) or (telnet localhost 2317)..." ); - - // ServerSocket waits for a connection from a client. - // Notice that it is outside the loop; ServerSocket needs to be made only once. - - int connectionCount = 0; // state variable - int totalEntrantCount = 31; // spoofed entrants - - ServerSocket serverSocket = new ServerSocket(2317); // server decides here what port to listen on. - // of interest: often client doesn't care what port it uses locally when connecting to that server port. - - // Loop, infinitely, waiting for client connections. - // Stop the program somewhere else. - while(true) - { - // blocks! then proceeds once a connection is "accept"ed - try (Socket clientConnection = serverSocket.accept()) { - connectionCount++; // got another one! - - OutputStream os = clientConnection.getOutputStream(); - PrintStream ps = new PrintStream(os); - - ps.println("This client response was written by server " + TcpExample2_Leckie_Mod_Hw1.class.getName()); // to remote client - System.out.println("This server response was written by server " + TcpExample2_Leckie_Mod_Hw1.class.getName()); // to server console - - ps.println("This is your lottery attempt number #" + connectionCount + ", you are aplicant number " + totalEntrantCount + " to try and win. Keep trying!"); - - totalEntrantCount = (totalEntrantCount + 79); - // Print some information locally about the Socket connection. - // This includes the port and IP numbers on both sides (the socket pair.) - - InetAddress localAddress = clientConnection.getLocalAddress(); - InetAddress remoteAddress = clientConnection.getInetAddress(); - - int localPort = clientConnection.getLocalPort(); - int remotePort = clientConnection.getPort(); // remember the prior question, why are 2 ports different? - - // My socket pair connection looks like this, to localhost: - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) note IPv6 - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) - // - // Why is first IP/port the same, while the second set has different ports? - - System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + - remoteAddress.toString() + ", " + remotePort + " ))"); - - System.out.println("got another connection, #" + connectionCount); // report progress - - // Notice the use of flush() and close(). Without - // the close() to Socket object may stay open for - // a while after the client has stopped needing this - // connection. Close() explicitly ends the connection. - ps.flush(); - } - } - } - catch(IOException e) - { - System.err.println("Problem with " + TcpExample2_Leckie_Mod_Hw1.class.getName() + " networking:"); // describe what is happening - System.err.println("Error: " + e); - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } - -} +package pkg3500.leckie; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * Very slightly more complex than example1. The only thing this does + * differently is introduce a loop into the response, so you don't + * have to restart the program after one response. Also, it prints + * out the socket pair the server sees. Run the program via telnet + * several times and compare the socket pairs. + * + * <code>telnet localhost 2317</code> + * + * If you're sophisticated you can contact the instructor's computer + * while running this program. + * + * <code>telnet ipOfServersLaptop 2317</code> + * + * And have that machine display the socket pairs received. + * @author mcgredo + * @author brutzman + * @author leckie + */ +public class TcpExample2_Leckie_Mod_Hw1 +{ + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) + { + try + { + System.out.println("TcpExample2ConnectionCounting has started and is waiting for a connection."); + System.out.println(" help: https://savage.nps.edu/Savage/developers.html#telnet"); + System.out.println(" enter (nc localhost 2317) or (telnet localhost 2317)..." ); + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket needs to be made only once. + + int connectionCount = 0; // state variable + int totalEntrantCount = 31; // spoofed entrants + + ServerSocket serverSocket = new ServerSocket(2317); // server decides here what port to listen on. + // of interest: often client doesn't care what port it uses locally when connecting to that server port. + + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while(true) + { + // blocks! then proceeds once a connection is "accept"ed + try (Socket clientConnection = serverSocket.accept()) { + connectionCount++; // got another one! + + OutputStream os = clientConnection.getOutputStream(); + PrintStream ps = new PrintStream(os); + + ps.println("This client response was written by server " + TcpExample2_Leckie_Mod_Hw1.class.getName()); // to remote client + System.out.println("This server response was written by server " + TcpExample2_Leckie_Mod_Hw1.class.getName()); // to server console + + ps.println("This is your lottery attempt number #" + connectionCount + ", you are aplicant number " + totalEntrantCount + " to try and win. Keep trying!"); + + totalEntrantCount = (totalEntrantCount + 79); + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair.) + + InetAddress localAddress = clientConnection.getLocalAddress(); + InetAddress remoteAddress = clientConnection.getInetAddress(); + + int localPort = clientConnection.getLocalPort(); + int remotePort = clientConnection.getPort(); // remember the prior question, why are 2 ports different? + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) note IPv6 + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + // + // Why is first IP/port the same, while the second set has different ports? + + System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + + remoteAddress.toString() + ", " + remotePort + " ))"); + + System.out.println("got another connection, #" + connectionCount); // report progress + + // Notice the use of flush() and close(). Without + // the close() to Socket object may stay open for + // a while after the client has stopped needing this + // connection. Close() explicitly ends the connection. + ps.flush(); + } + } + } + catch(IOException e) + { + System.err.println("Problem with " + TcpExample2_Leckie_Mod_Hw1.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/AllenTcpExample3Client.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/AllenTcpExample3Client.java index ef9b10791b649039f00c9d6260a0919c9fa49d9a..2184a1be395895c4fc9da11d10e3129698c901b7 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/AllenTcpExample3Client.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/AllenTcpExample3Client.java @@ -24,6 +24,7 @@ public class AllenTcpExample3Client { /** * Program invocation, execution starts here * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution */ public static void main(String[] args) throws InterruptedException { diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherClient.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherClient.java index 00de0484e3b43b1a65a98be8f45d2ab5f96f8339..ea2fe6d1b86c55f4195b84cecaf7643e03a12c4c 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherClient.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherClient.java @@ -19,9 +19,10 @@ import java.net.Socket; * * @author adfis */ -public class FisherClient { - +public class FisherClient +{ // IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + /** socket parameter of interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // Sub with someone's IP // Got it to work with McNeely in class diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankClient.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankClient.java index 843cb90791f7b72838d87c2ec2f76d7b285790e8..1e8440366cc60797eb19efcdc0f48a358bbbdf2b 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankClient.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankClient.java @@ -1,109 +1,109 @@ -package MV3500Cohort2021JulySeptember.homework2.Frank; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.PrintStream; -import java.io.Reader; -import java.net.Socket; - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -/** - * - * @author justi - */ -public class FrankClient { - - /** - */ - public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; - - /** - * Program invocation, execution starts here - * - * @param args command-line arguments - * @throws java.lang.InterruptedException - */ - public static void main(String[] args) throws InterruptedException { - - // Local variables/fields - Socket socket = null; - InputStream is; - Reader isr; - BufferedReader br; - String serverMessage; - int clientLoopCount = 0; - OutputStream os; - PrintStream ps; - - - try { - while (true) { - clientLoopCount++; // increment at beginning of loop for reliability - System.out.println( "creating socket..."); - - // We request an IP to connect to ("localhost") and - // port number at that IP (2318). This establishes - // a connection to that IP in the form of a Socket - // object; the server uses a ServerSocket to wait for - // connections. - socket = new Socket(LOCALHOST, 2318); // locohost? - - // Now hook everything up (i.e. set up the streams), Java style: - is = socket.getInputStream(); - isr = new InputStreamReader(is); - br = new BufferedReader(isr); - - // Read a single line written by the server. We'd - // do things a bit differently if there were many lines to be read - // from the server instead of one only. - serverMessage = br.readLine(); - System.out.println("*********************************"); - - System.out.print( clientLoopCount + ": "); - System.out.println("Hola!"); - System.out.println("The message the server sent was: '" + serverMessage + "'"); - - - -// socket gets closed, either automatically/silently by this code (or possibly by the server) - if (serverMessage.equals("this is good bye message from Franks server")) { //if client recieved termanation message stop client - break; - } - os = socket.getOutputStream(); - ps = new PrintStream(os); - ps.println("I'm doing well!"); // this gets sent back to server - ps.flush(); - - Thread.sleep(1000); // turned it down to 1 second - - } // end while(true) // infinite loops are dangerous, be sure to kill this process! - } catch (IOException e) { - System.err.println("Problem with " + FrankClient.class.getName() + " networking:"); // describe what is happening - System.err.println("Error: " + e); - - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) { - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } finally // occurs after any other activity when shutting down - { - try { - if (socket != null) { - socket.close(); - } - } catch (IOException e) { - } - - // program exit: tell somebody about that happening. Likely cause: server drops connection. - System.out.println(); - System.out.println("Good Bye!!!"); - } - } -} +package MV3500Cohort2021JulySeptember.homework2.Frank; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintStream; +import java.io.Reader; +import java.net.Socket; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author justi + */ +public class FrankClient { + + /** + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + OutputStream os; + PrintStream ps; + + + try { + while (true) { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println( "creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2318). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2318); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("*********************************"); + + System.out.print( clientLoopCount + ": "); + System.out.println("Hola!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + + + +// socket gets closed, either automatically/silently by this code (or possibly by the server) + if (serverMessage.equals("this is good bye message from Franks server")) { //if client recieved termanation message stop client + break; + } + os = socket.getOutputStream(); + ps = new PrintStream(os); + ps.println("I'm doing well!"); // this gets sent back to server + ps.flush(); + + Thread.sleep(1000); // turned it down to 1 second + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } catch (IOException e) { + System.err.println("Problem with " + FrankClient.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } finally // occurs after any other activity when shutting down + { + try { + if (socket != null) { + socket.close(); + } + } catch (IOException e) { + } + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println("Good Bye!!!"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankServer.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankServer.java index 601dee98773668ad0825792b46761da94bf52af8..864516dda793c18c1d042be86e063df40a433e6c 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankServer.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankServer.java @@ -1,98 +1,98 @@ -package MV3500Cohort2021JulySeptember.homework2.Frank; - -import java.io.*; -import java.net.*; - - -public class FrankServer { - - /** - * Program invocation, execution starts here If already compiled, can run - * using console in directory ../../build/classes/ by invoking \ java - * -classpath .TcpExamples.TcpExample3Server - * - * @param args command-line arguments - * @throws java.lang.InterruptedException - */ - public static void main(String[] args) throws InterruptedException { - try { - - // ServerSocket waits for a connection from a client. - // Notice that it is outside the loop; ServerSocket - // needs to be made only once. - System.out.println(FrankServer.class.getName() + " has started..."); // it helps debugging to put this on console first - - ServerSocket serverSocket = new ServerSocket(2318); // changed from 2317 to 2318 - OutputStream os; - PrintStream ps; - InetAddress localAddress, remoteAddress; - int localPort, remotePort; - int serverLoopCount = 0; - InputStream is; - InputStreamReader isr; - BufferedReader br; - String clientMessage; - - // Server is up and waiting (i.e. "blocked" or paused) - // Loop, infinitely, waiting for client connections. - // Stop the program somewhere else. - while (true) { - - // block until connected to a client - try ( Socket clientConnectionSocket = serverSocket.accept()) { - serverLoopCount++; // increment at beginning of loop for reliability - - // Now hook everything up (i.e. set up the streams), Java style: - os = clientConnectionSocket.getOutputStream(); - ps = new PrintStream(os); - if (serverLoopCount <= 10) { // checking if the loop count <= 10 - ps.println("How are you doing?"); // this gets sent back to client! - } else { - ps.println("this is good bye message from Franks server"); // termination after 20 messages - break; // Stop server - } - // Print some information locally about the Socket connection. - // This includes the port and IP numbers on both sides (the socket pair). - localAddress = clientConnectionSocket.getLocalAddress(); - remoteAddress = clientConnectionSocket.getInetAddress(); - localPort = clientConnectionSocket.getLocalPort(); - remotePort = clientConnectionSocket.getPort(); - - System.out.print("Server loop " + serverLoopCount + ": "); - - // My socket pair connection looks like this, to localhost: - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) - // Why is the first IP/port the same, while the second set has different ports? - System.out.println(FrankServer.class.getName() + " socket pair showing host name, address, port:"); - System.out.println(" (( " - + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " - + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); - - if (localAddress.getHostName().equals(localAddress.getHostAddress()) - || remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) { - System.out.println(" note HostName matches address if host has no DNS name"); - } - is = clientConnectionSocket.getInputStream(); - isr = new InputStreamReader(is); - br = new BufferedReader(isr); - clientMessage = br.readLine(); - System.out.println("The message the client sent was: '" + clientMessage + "'");// Displaying the message the client sent - // Not/*i*/ce the use of flush() and try w/ resources. Without - // the try w/ resources the Socket object may stay open for - // a while after the client has stopped needing this - // connection. try w/ resources explicitly ends the connection. - ps.flush(); - // like it or not, you're outta here! - } - } - } catch (IOException e) { - System.err.println("Problem with " + FrankServer.class.getName() + " networking: " + e); - - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) { - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } - } -} +package MV3500Cohort2021JulySeptember.homework2.Frank; + +import java.io.*; +import java.net.*; + + +public class FrankServer { + + /** + * Program invocation, execution starts here If already compiled, can run + * using console in directory ../../build/classes/ by invoking \ java + * -classpath .TcpExamples.TcpExample3Server + * + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution + */ + public static void main(String[] args) throws InterruptedException { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(FrankServer.class.getName() + " has started..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2318); // changed from 2317 to 2318 + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + InputStream is; + InputStreamReader isr; + BufferedReader br; + String clientMessage; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try ( Socket clientConnectionSocket = serverSocket.accept()) { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + if (serverLoopCount <= 10) { // checking if the loop count <= 10 + ps.println("How are you doing?"); // this gets sent back to client! + } else { + ps.println("this is good bye message from Franks server"); // termination after 20 messages + break; // Stop server + } + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print("Server loop " + serverLoopCount + ": "); + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(FrankServer.class.getName() + " socket pair showing host name, address, port:"); + System.out.println(" (( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + if (localAddress.getHostName().equals(localAddress.getHostAddress()) + || remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) { + System.out.println(" note HostName matches address if host has no DNS name"); + } + is = clientConnectionSocket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + clientMessage = br.readLine(); + System.out.println("The message the client sent was: '" + clientMessage + "'");// Displaying the message the client sent + // Not/*i*/ce the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + FrankServer.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankClient.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankClient.java index 4f7c74c90157a82ae7a87ea11edeb1505644ab9b..7a47fc9139e04f668c57b2448f8f907fc511b538 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankClient.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankClient.java @@ -1,99 +1,99 @@ -package MV3500Cohort2021JulySeptember.homework2; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.Socket; - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -/** - * - * @author justi - */ -public class FrankClient { - - /** - */ - public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; - - /** - * Program invocation, execution starts here - * - * @param args command-line arguments - * @throws java.lang.InterruptedException - */ - public static void main(String[] args) throws InterruptedException { - - // Local variables/fields - Socket socket = null; - InputStream is; - Reader isr; - BufferedReader br; - String serverMessage; - int clientLoopCount = 0; - - try { - while (true) { - clientLoopCount++; // increment at beginning of loop for reliability - System.out.println( "creating socket..."); - - // We request an IP to connect to ("localhost") and - // port number at that IP (2317). This establishes - // a connection to that IP in the form of a Socket - // object; the server uses a ServerSocket to wait for - // connections. - socket = new Socket(LOCALHOST, 2318); // locohost? - - // Now hook everything up (i.e. set up the streams), Java style: - is = socket.getInputStream(); - isr = new InputStreamReader(is); - br = new BufferedReader(isr); - - // Read a single line written by the server. We'd - // do things a bit differently if there were many lines to be read - // from the server instead of one only. - serverMessage = br.readLine(); - System.out.println("*********************************"); - - System.out.print( clientLoopCount + ": "); - System.out.println("Hola!"); - System.out.println("The message the server sent was: '" + serverMessage + "'"); - int count = 0; - System.out.println("test"); - count++; -// socket gets closed, either automatically/silently by this code (or possibly by the server) - if (serverMessage.equals("this is good bye message from Franks server")) { //if client recieved termanation message stop client - break; - } - Thread.sleep(1000); // turned it down to 1 second - - } // end while(true) // infinite loops are dangerous, be sure to kill this process! - } catch (IOException e) { - System.err.println("Problem with " + FrankClient.class.getName() + " networking:"); // describe what is happening - System.err.println("Error: " + e); - - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) { - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } finally // occurs after any other activity when shutting down - { - try { - if (socket != null) { - socket.close(); - } - } catch (IOException e) { - } - - // program exit: tell somebody about that happening. Likely cause: server drops connection. - System.out.println(); - System.out.println("Good Bye!!!"); - } - } -} +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.Socket; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author justi + */ +public class FrankClient { + + /** + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println( "creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2318); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("*********************************"); + + System.out.print( clientLoopCount + ": "); + System.out.println("Hola!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + int count = 0; + System.out.println("test"); + count++; +// socket gets closed, either automatically/silently by this code (or possibly by the server) + if (serverMessage.equals("this is good bye message from Franks server")) { //if client recieved termanation message stop client + break; + } + Thread.sleep(1000); // turned it down to 1 second + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } catch (IOException e) { + System.err.println("Problem with " + FrankClient.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } finally // occurs after any other activity when shutting down + { + try { + if (socket != null) { + socket.close(); + } + } catch (IOException e) { + } + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println("Good Bye!!!"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankServer.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankServer.java index 6d7fb253e38c748dd99970f504bace3f3452aef2..aafe9a4a2ee3a0126f26a4f906abf699ea2a5864 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankServer.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankServer.java @@ -1,89 +1,90 @@ -package MV3500Cohort2021JulySeptember.homework2; - -import java.io.*; -import java.net.*; - - -public class FrankServer { - - /** - * Program invocation, execution starts here If already compiled, can run - * using console in directory ../../build/classes/ by invoking \ java - * -classpath . TcpExamples.TcpExample3Server - * - * @param args command-line arguments - */ - public static void main(String[] args) throws InterruptedException { - try { - - // ServerSocket waits for a connection from a client. - // Notice that it is outside the loop; ServerSocket - // needs to be made only once. - System.out.println(FrankServer.class.getName() + " has started..."); // it helps debugging to put this on console first - - ServerSocket serverSocket = new ServerSocket(2318); // changed from 2317 to 2318 - OutputStream os; - PrintStream ps; - InetAddress localAddress, remoteAddress; - int localPort, remotePort; - int serverLoopCount = 0; - - // Server is up and waiting (i.e. "blocked" or paused) - // Loop, infinitely, waiting for client connections. - // Stop the program somewhere else. - while (true) { - - // block until connected to a client - try ( Socket clientConnectionSocket = serverSocket.accept()) { - serverLoopCount++; // increment at beginning of loop for reliability - - // Now hook everything up (i.e. set up the streams), Java style: - os = clientConnectionSocket.getOutputStream(); - ps = new PrintStream(os); - if (serverLoopCount <= 10) { // checking if the loop count <= 10 - ps.println("How are you doing?"); // this gets sent back to client! - } else { - ps.println("this is good bye message from Franks server"); // termination after 20 messages - break; // Stop server - } - // Print some information locally about the Socket connection. - // This includes the port and IP numbers on both sides (the socket pair). - localAddress = clientConnectionSocket.getLocalAddress(); - remoteAddress = clientConnectionSocket.getInetAddress(); - localPort = clientConnectionSocket.getLocalPort(); - remotePort = clientConnectionSocket.getPort(); - - System.out.print("Server loop " + serverLoopCount + ": "); - - // My socket pair connection looks like this, to localhost: - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) - // Why is the first IP/port the same, while the second set has different ports? - System.out.println(FrankServer.class.getName() + " socket pair showing host name, address, port:"); - System.out.println(" (( " - + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " - + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); - - if (localAddress.getHostName().equals(localAddress.getHostAddress()) - || remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) { - System.out.println(" note HostName matches address if host has no DNS name"); - } - - // Not/*i*/ce the use of flush() and try w/ resources. Without - // the try w/ resources the Socket object may stay open for - // a while after the client has stopped needing this - // connection. try w/ resources explicitly ends the connection. - ps.flush(); - // like it or not, you're outta here! - } - } - } catch (IOException e) { - System.err.println("Problem with " + FrankServer.class.getName() + " networking: " + e); - - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) { - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } - } -} +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.*; +import java.net.*; + + +public class FrankServer { + + /** + * Program invocation, execution starts here If already compiled, can run + * using console in directory ../../build/classes/ by invoking \ java + * -classpath . TcpExamples.TcpExample3Server + * + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution + */ + public static void main(String[] args) throws InterruptedException { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(FrankServer.class.getName() + " has started..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2318); // changed from 2317 to 2318 + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try ( Socket clientConnectionSocket = serverSocket.accept()) { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + if (serverLoopCount <= 10) { // checking if the loop count <= 10 + ps.println("How are you doing?"); // this gets sent back to client! + } else { + ps.println("this is good bye message from Franks server"); // termination after 20 messages + break; // Stop server + } + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print("Server loop " + serverLoopCount + ": "); + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(FrankServer.class.getName() + " socket pair showing host name, address, port:"); + System.out.println(" (( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + if (localAddress.getHostName().equals(localAddress.getHostAddress()) + || remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) { + System.out.println(" note HostName matches address if host has no DNS name"); + } + + // Not/*i*/ce the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + FrankServer.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Client.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Client.java index 31884977d83f96c54aa88b3106fc137020502d85..59842415433cd6df81d943477b2c6af87b316d61 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Client.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Client.java @@ -1,96 +1,96 @@ -package MV3500Cohort2021JulySeptember.homework2; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.Socket; - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -/** - * - * @author justi - */ -public class FrankTcpExample3Client { - - /** - */ - public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; - - /** - * Program invocation, execution starts here - * - * @param args command-line arguments - * @throws java.lang.InterruptedException - */ - public static void main(String[] args) throws InterruptedException { - - // Local variables/fields - Socket socket = null; - InputStream is; - Reader isr; - BufferedReader br; - String serverMessage; - int clientLoopCount = 0; - - try { - while (true) { - clientLoopCount++; // increment at beginning of loop for reliability - System.out.println( "creating socket..."); - - // We request an IP to connect to ("localhost") and - // port number at that IP (2317). This establishes - // a connection to that IP in the form of a Socket - // object; the server uses a ServerSocket to wait for - // connections. - socket = new Socket(LOCALHOST, 2318); // locohost? - - // Now hook everything up (i.e. set up the streams), Java style: - is = socket.getInputStream(); - isr = new InputStreamReader(is); - br = new BufferedReader(isr); - - // Read a single line written by the server. We'd - // do things a bit differently if there were many lines to be read - // from the server instead of one only. - serverMessage = br.readLine(); - System.out.println("*********************************"); - - System.out.print( clientLoopCount + ": "); - System.out.println("Hola!"); - System.out.println("The message the server sent was: '" + serverMessage + "'"); - // socket gets closed, either automatically/silently by this code (or possibly by the server) - if (serverMessage.equals("this is good bye message from Franks server")) { //if client recieved termanation message stop client - break; - } - Thread.sleep(1000); // turned it down to 1 second - - } // end while(true) // infinite loops are dangerous, be sure to kill this process! - } catch (IOException e) { - System.err.println("Problem with " + FrankTcpExample3Client.class.getName() + " networking:"); // describe what is happening - System.err.println("Error: " + e); - - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) { - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } finally // occurs after any other activity when shutting down - { - try { - if (socket != null) { - socket.close(); - } - } catch (IOException e) { - } - - // program exit: tell somebody about that happening. Likely cause: server drops connection. - System.out.println(); - System.out.println("Good Bye!!!"); - } - } -} +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.Socket; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author justi + */ +public class FrankTcpExample3Client { + + /** + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println( "creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2318); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("*********************************"); + + System.out.print( clientLoopCount + ": "); + System.out.println("Hola!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + // socket gets closed, either automatically/silently by this code (or possibly by the server) + if (serverMessage.equals("this is good bye message from Franks server")) { //if client recieved termanation message stop client + break; + } + Thread.sleep(1000); // turned it down to 1 second + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } catch (IOException e) { + System.err.println("Problem with " + FrankTcpExample3Client.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } finally // occurs after any other activity when shutting down + { + try { + if (socket != null) { + socket.close(); + } + } catch (IOException e) { + } + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println("Good Bye!!!"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Server.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Server.java index f292beed04f1b29c108fb5a8e8cfccedb85452bc..037239a06f9d2e3f4f4685f20e94da4afe79178b 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Server.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Server.java @@ -1,89 +1,90 @@ -package MV3500Cohort2021JulySeptember.homework2; - -import java.io.*; -import java.net.*; - - -public class FrankTcpExample3Server { - - /** - * Program invocation, execution starts here If already compiled, can run - * using console in directory ../../build/classes/ by invoking \ java - * -classpath . TcpExamples.TcpExample3Server - * - * @param args command-line arguments - */ - public static void main(String[] args) throws InterruptedException { - try { - - // ServerSocket waits for a connection from a client. - // Notice that it is outside the loop; ServerSocket - // needs to be made only once. - System.out.println(FrankTcpExample3Server.class.getName() + " has started..."); // it helps debugging to put this on console first - - ServerSocket serverSocket = new ServerSocket(2318); // changed from 2317 to 2318 - OutputStream os; - PrintStream ps; - InetAddress localAddress, remoteAddress; - int localPort, remotePort; - int serverLoopCount = 0; - - // Server is up and waiting (i.e. "blocked" or paused) - // Loop, infinitely, waiting for client connections. - // Stop the program somewhere else. - while (true) { - - // block until connected to a client - try ( Socket clientConnectionSocket = serverSocket.accept()) { - serverLoopCount++; // increment at beginning of loop for reliability - - // Now hook everything up (i.e. set up the streams), Java style: - os = clientConnectionSocket.getOutputStream(); - ps = new PrintStream(os); - if (serverLoopCount <= 10) { // checking if the loop count <= 10 - ps.println("How are you doing?"); // this gets sent back to client! - } else { - ps.println("this is good bye message from Franks server"); // termination after 20 messages - break; // Stop server - } - // Print some information locally about the Socket connection. - // This includes the port and IP numbers on both sides (the socket pair). - localAddress = clientConnectionSocket.getLocalAddress(); - remoteAddress = clientConnectionSocket.getInetAddress(); - localPort = clientConnectionSocket.getLocalPort(); - remotePort = clientConnectionSocket.getPort(); - - System.out.print("Server loop " + serverLoopCount + ": "); - - // My socket pair connection looks like this, to localhost: - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) - // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) - // Why is the first IP/port the same, while the second set has different ports? - System.out.println(FrankTcpExample3Server.class.getName() + " socket pair showing host name, address, port:"); - System.out.println(" (( " - + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " - + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); - - if (localAddress.getHostName().equals(localAddress.getHostAddress()) - || remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) { - System.out.println(" note HostName matches address if host has no DNS name"); - } - - // Not/*i*/ce the use of flush() and try w/ resources. Without - // the try w/ resources the Socket object may stay open for - // a while after the client has stopped needing this - // connection. try w/ resources explicitly ends the connection. - ps.flush(); - // like it or not, you're outta here! - } - } - } catch (IOException e) { - System.err.println("Problem with " + FrankTcpExample3Server.class.getName() + " networking: " + e); - - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) { - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } - } -} +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.*; +import java.net.*; + + +public class FrankTcpExample3Server { + + /** + * Program invocation, execution starts here If already compiled, can run + * using console in directory ../../build/classes/ by invoking \ java + * -classpath . TcpExamples.TcpExample3Server + * + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution + */ + public static void main(String[] args) throws InterruptedException { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(FrankTcpExample3Server.class.getName() + " has started..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2318); // changed from 2317 to 2318 + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try ( Socket clientConnectionSocket = serverSocket.accept()) { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + if (serverLoopCount <= 10) { // checking if the loop count <= 10 + ps.println("How are you doing?"); // this gets sent back to client! + } else { + ps.println("this is good bye message from Franks server"); // termination after 20 messages + break; // Stop server + } + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print("Server loop " + serverLoopCount + ": "); + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(FrankTcpExample3Server.class.getName() + " socket pair showing host name, address, port:"); + System.out.println(" (( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + if (localAddress.getHostName().equals(localAddress.getHostAddress()) + || remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) { + System.out.println(" note HostName matches address if host has no DNS name"); + } + + // Not/*i*/ce the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + FrankTcpExample3Server.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/LeckieClient.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/LeckieClient.java index 3dac42ae73832877e0eeeb318db292023e0532af..a562830b2833c68dcfd03e7b646847bbbf08ba9a 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/LeckieClient.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/LeckieClient.java @@ -1,86 +1,87 @@ -package MV3500Cohort2021JulySeptember.homework2.Leckie; -import java.io.*; -import java.net.*; - -/** - * - * @author Jacob Leckie - */ -public class LeckieClient { - - /** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 - * @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a> - * @see <a href="https://en.wikipedia.org/wiki/IPv6_address">https://en.wikipedia.org/wiki/IPv6_address</a> - */ - public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; - - /** - * Program invocation, execution starts here - * @param args command-line arguments - */ - public static void main(String[] args) throws InterruptedException { - - // Local variables/fields - Socket socket = null; - InputStream is; - Reader isr; - BufferedReader br; - String serverMessage; - int clientLoopCount = 0; - - try { - while (true) - { - clientLoopCount++; // increment at beginning of loop for reliability - System.out.println(LeckieClient.class.getName() + " creating socket..."); - - // We request an IP to connect to ("localhost") and - // port number at that IP (2317). This establishes - // a connection to that IP in the form of a Socket - // object; the server uses a ServerSocket to wait for - // connections. - socket = new Socket(LOCALHOST, 2317); // locohost? - - // Now hook everything up (i.e. set up the streams), Java style: - is = socket.getInputStream(); - isr = new InputStreamReader(is); - br = new BufferedReader(isr); - - // Read a single line written by the server. We'd - // do things a bit differently if there were many lines to be read - // from the server instead of one only. - serverMessage = br.readLine(); - System.out.println("=================================================="); - -// System.out.print ("Client loop " + clientLoopCount + ": "); - System.out.println("I dont want to clean my room!"); - System.out.println("The message the server sent was: '" + serverMessage + "'"); - // socket gets closed, either automatically/silently by this code (or possibly by the server) - - Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec (1/2 second) - - } // end while(true) // infinite loops are dangerous, be sure to kill this process! - } - catch (IOException e) - { - System.err.println("Problem with " + LeckieClient.class.getName() + " networking:"); // describe what is happening - System.err.println("Error: " + e); - - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) { - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } - finally // occurs after any other activity when shutting down - { - try { - if (socket != null) - socket.close(); - } catch (IOException e) {} - - // program exit: tell somebody about that happening. Likely cause: server drops connection. - System.out.println(); - System.out.println(LeckieClient.class.getName() + " exit"); - } - } -} +package MV3500Cohort2021JulySeptember.homework2.Leckie; +import java.io.*; +import java.net.*; + +/** + * + * @author Jacob Leckie + */ +public class LeckieClient { + + /** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + * @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a> + * @see <a href="https://en.wikipedia.org/wiki/IPv6_address">https://en.wikipedia.org/wiki/IPv6_address</a> + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels program + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) + { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println(LeckieClient.class.getName() + " creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2317); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("=================================================="); + +// System.out.print ("Client loop " + clientLoopCount + ": "); + System.out.println("I dont want to clean my room!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + // socket gets closed, either automatically/silently by this code (or possibly by the server) + + Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec (1/2 second) + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } + catch (IOException e) + { + System.err.println("Problem with " + LeckieClient.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + finally // occurs after any other activity when shutting down + { + try { + if (socket != null) + socket.close(); + } catch (IOException e) {} + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println(LeckieClient.class.getName() + " exit"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/McNeely/McNeelyTCPExample3Client.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/McNeely/McNeelyTCPExample3Client.java index 8e495a0b9649ac5266259d5ba73a5546a2d054b0..221949b5bcee43ca55b39659123b22881baa2806 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/McNeely/McNeelyTCPExample3Client.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/McNeely/McNeelyTCPExample3Client.java @@ -1,93 +1,94 @@ -package MV3500Cohort2021JulySeptember.homework2.McNeely; - -import java.io.*; -import java.net.*; - -/** - * Before, we always used telnet (netcat) to connect to the server. Here we are - * now writing our own program to do the connection. - * - * As you will see, when we run this after we start the server we will see the - * same string telnet printed, sent by the server. The output at the server will - * show different socket pairs for each time the loop iterates. - * - * @author jrm_u - */ -public class McNeelyTCPExample3Client { - - /** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 - * @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a> - * @see <a href="https://en.wikipedia.org/wiki/IPv6_address">https://en.wikipedia.org/wiki/IPv6_address</a> - */ - public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; - - /** - * Program invocation, execution starts here - * @param args command-line arguments - */ - public static void main(String[] args) throws InterruptedException { - - // Local variables/fields - Socket socket = null; - InputStream is; - Reader isr; - BufferedReader br; - String serverMessage; - int clientLoopCount = 0; - - try { - while (true) - { - clientLoopCount++; // increment at beginning of loop for reliability - System.out.println(McNeelyTCPExample3Client.class.getName() + "McNeely creating socket..."); - - // We request an IP to connect to ("localhost") and - // port number at that IP (2317). This establishes - // a connection to that IP in the form of a Socket - // object; the server uses a ServerSocket to wait for - // connections. - socket = new Socket(LOCALHOST, 2317); // locohost? - - // Now hook everything up (i.e. set up the streams), Java style: - is = socket.getInputStream(); - isr = new InputStreamReader(is); - br = new BufferedReader(isr); - - // Read a single line written by the server. We'd - // do things a bit differently if there were many lines to be read - // from the server instead of one only. - serverMessage = br.readLine(); - System.out.println("=================================================="); - - System.out.print ("Client loop " + clientLoopCount + ": "); - System.out.println("now we're cooking with diesel fuel!"); - System.out.println("The message the server sent was: '" + serverMessage + "'"); - // socket gets closed, either automatically/silently by this code (or possibly by the server) - - Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec - - } // end while(true) // infinite loops are dangerous, be sure to kill this process! - } - catch (IOException e) - { - System.err.println("Problem with " + McNeelyTCPExample3Client.class.getName() + " networking:"); // describe what is happening - System.err.println("Error: " + e); - - // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) { - System.err.println("*** Be sure to stop any other running instances of programs using this port!"); - } - } - finally // occurs after any other activity when shutting down - { - try { - if (socket != null) - socket.close(); - } catch (IOException e) {} - - // program exit: tell somebody about that happening. Likely cause: server drops connection. - System.out.println(); - System.out.println(McNeelyTCPExample3Client.class.getName() + " exit"); - } - } -} +package MV3500Cohort2021JulySeptember.homework2.McNeely; + +import java.io.*; +import java.net.*; + +/** + * Before, we always used telnet (netcat) to connect to the server. Here we are + * now writing our own program to do the connection. + * + * As you will see, when we run this after we start the server we will see the + * same string telnet printed, sent by the server. The output at the server will + * show different socket pairs for each time the loop iterates. + * + * @author jrm_u + */ +public class McNeelyTCPExample3Client { + + /** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + * @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a> + * @see <a href="https://en.wikipedia.org/wiki/IPv6_address">https://en.wikipedia.org/wiki/IPv6_address</a> + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) + { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println(McNeelyTCPExample3Client.class.getName() + "McNeely creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2317); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("=================================================="); + + System.out.print ("Client loop " + clientLoopCount + ": "); + System.out.println("now we're cooking with diesel fuel!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + // socket gets closed, either automatically/silently by this code (or possibly by the server) + + Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } + catch (IOException e) + { + System.err.println("Problem with " + McNeelyTCPExample3Client.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + finally // occurs after any other activity when shutting down + { + try { + if (socket != null) + socket.close(); + } catch (IOException e) {} + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println(McNeelyTCPExample3Client.class.getName() + " exit"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/MorrisTCPExample3Client.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/MorrisTCPExample3Client.java index 1eb66d23a88cb5160dba541a39bb75dd06e608df..1464b865580f738842569c01878f7ba40a6af9b9 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/MorrisTCPExample3Client.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/MorrisTCPExample3Client.java @@ -23,6 +23,7 @@ public class MorrisTCPExample3Client { /** * Program invocation, execution starts here * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution */ public static void main(String[] args) throws InterruptedException { diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Client_homework2.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Client_homework2.java index 31734f0c3cbdfd0fc34a01c0c4a62ac41953bf82..48c6e8de5afd18679b6289336b94cf1ca6e1ac8d 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Client_homework2.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Client_homework2.java @@ -31,6 +31,7 @@ public class Pugh3Client_homework2 { * Program invocation, execution starts here * * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution */ public static void main(String[] args) throws InterruptedException { diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/ReynoldsTcpExample3Client.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/ReynoldsTcpExample3Client.java index 7d5dbec55a350f8ac33103692a6c7f93abd7d2fe..3ffc35822e0bc7acd21a856e8afb7d9e938bb992 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/ReynoldsTcpExample3Client.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/ReynoldsTcpExample3Client.java @@ -26,6 +26,7 @@ public class ReynoldsTcpExample3Client { /** * Program invocation, execution starts here * @param args command-line arguments + * @throws java.lang.InterruptedException user cancels execution */ public static void main(String[] args) throws InterruptedException {