Skip to content
Snippets Groups Projects
Commit 15045456 authored by brutzman's avatar brutzman
Browse files

documentation improvements

parent b492714e
No related branches found
No related tags found
No related merge requests found
......@@ -20,10 +20,12 @@ public class UdpSender
{
// 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)
public static final int SENDING_PORT = 1414;
// public static final int SENDING_PORT = 1414; // not needed, can let system choose an open local port
public static final int RECEIVING_PORT = 1415;
public static final int TOTAL_PACKETS_TO_SEND = 100;
public static final String DESTINATION_HOST = "localhost"; // localhost 127.0.0.1 or argon 10.1.105.1
// here is what we need for lab comms
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")
public static void main(String[] args) throws IOException
......@@ -32,7 +34,7 @@ public class UdpSender
DataOutputStream dos = null;
int packetID = 0; // counter variable to send in packet
float value = -1.0f; // unreachable value is good sentinel to ensure expected changes occur
String message = "Hello MV3500"; // no really
String message = MY_NAME + " says Hello MV3500"; // no really
String padding = new String();
try
......@@ -41,7 +43,7 @@ public class UdpSender
System.out.println(UdpSender.class.getName() + " started...");
// Create a UDP socket
udpSocket = new DatagramSocket(SENDING_PORT);
udpSocket = new DatagramSocket(); // let system assign output port, then SENDING_PORT not needed
// Put together a message with binary content. "ByteArrayOutputStream"
// is a java.io utility that lets us put together an array of binary
......@@ -82,6 +84,7 @@ public class UdpSender
byteArray = baos.toByteArray(); // OK so go get the flushed result...
datagramPacket.setData(byteArray); // and put it in the packet...
udpSocket.send(datagramPacket); // and send it away. boom gone, nonblocking.
// System.out.println("udpSocket output port=" + udpSocket.getLocalPort()); // diagnostic tells what port was chosen by system
if (isPacketIdEvenParity)
padding = " ";
......
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