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

multiple changes during gitlab lockout, mostly javadoc

parent cac0bda6
No related branches found
No related tags found
No related merge requests found
package MV3500Cohort2018JanuaryMarch.homework2; package MV3500Cohort2018JanuaryMarch.homework2;
/** /**
* This assignment uses the code from MV3500 example "multicastExample1" * This assignment uses the code from MV3500 example "multicastExample1"
* modifications were made to the packet creation and where the packet is * modifications were made to the packet creation and where the packet is
* assembled. * assembled.
* *
* @author Brian * @author Brian
*/ */
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
public class TackettMulticastSender { public class TackettMulticastSender {
public static final String MULTICAST_ADDRESS = "172.20.144.145"; public static final String MULTICAST_ADDRESS = "172.20.144.145";
public static final int DESTINATION_PORT = 1717; public static final int DESTINATION_PORT = 1717;
/** How many routers can be crossed */ /** How many routers can be crossed */
public static final int TTL = 10; public static final int TTL = 10;
private int velocity; private int velocity;
private float xPos; private float xPos;
private float yPos; private float yPos;
/**
public static void main(String[] args) * Program execution commences here
{ * @param args Command-line arguments (unused)
int velocity = 3; */
int direction = 180; public static void main(String[] args)
double xPos = 0; {
double yPos = 2; int velocity = 3;
int direction = 180;
double xPos = 0;
try double yPos = 2;
{
// This is a java/IPv6 problem. You should also add it to the
// arguments used to start the app, eg -Djava.net.preferIPv4Stack=true try
// set in the "run" section of preferences. Also, typically {
// netbeans must be restarted after these settings. // This is a java/IPv6 problem. You should also add it to the
// https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache // arguments used to start the app, eg -Djava.net.preferIPv4Stack=true
System.setProperty("java.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
MulticastSocket multicastSocket = new MulticastSocket(1718); System.setProperty("java.net.preferIPv4Stack", "true");
multicastSocket.setTimeToLive(TTL);
InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS);
System.out.println(multicastAddress); MulticastSocket multicastSocket = new MulticastSocket(1718);
// Join group useful on receiving side multicastSocket.setTimeToLive(TTL);
multicastSocket.joinGroup(multicastAddress); InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS);
// You can join multiple groups here System.out.println(multicastAddress);
// Join group useful on receiving side
multicastSocket.joinGroup(multicastAddress);
// How fast does this go? Does UDP try to slow it down, or does // You can join multiple groups here
// 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 // How fast does this go? Does UDP try to slow it down, or does
// order packet, or dropped packet? // this cause network problems? (hint: yes for an unlimited send
// rate, unlike TCP). How do you know on the receiving side
for(int idx = 0; idx < 100; idx++) // that you haven't received a duplicate UDP packet, out of
{ // order packet, or dropped packet?
xPos = xPos + (Math.cos(Math.toRadians(direction))*velocity); //computes the horixontal displacement for each movement based on velocity - this is a fixed velocity and time increment for(int idx = 0; idx < 100; idx++)
yPos = yPos + (Math.sin(Math.toRadians(direction))*velocity); //computes the vertical displacement for each movement based on velocity - this is a fixed velocity and time increment {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); xPos = xPos + (Math.cos(Math.toRadians(direction))*velocity); //computes the horixontal displacement for each movement based on velocity - this is a fixed velocity and time increment
DataOutputStream dos = new DataOutputStream(baos); yPos = yPos + (Math.sin(Math.toRadians(direction))*velocity); //computes the vertical displacement for each movement based on velocity - this is a fixed velocity and time increment
dos.writeDouble(xPos);
dos.writeDouble(yPos); ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeDouble(xPos);
byte[] buffer = baos.toByteArray(); dos.writeDouble(yPos);
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT);
byte[] buffer = baos.toByteArray();
multicastSocket.send(packet);
baos.reset(); DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT);
Thread.sleep(1000); // Send 100, one per second
System.out.println("Sent multicast packet " + idx + " of 100"); multicastSocket.send(packet);
} baos.reset();
} Thread.sleep(1000); // Send 100, one per second
catch(Exception e) System.out.println("Sent multicast packet " + idx + " of 100");
{ }
System.out.println(e); }
} catch(Exception e)
} {
System.out.println(e);
} }
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment