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

UdpSender is sending but not properly connecting to UdpReceiver, debugging in progress

parent fcdc3758
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,8 @@ import java.net.*;
* for each. This prevents collision complaints from the localhost.
*
* Start this before launching UdpSender.
*
*
* @see <a href=" https://docs.oracle.com/javase/tutorial/networking/datagrams/index.html"> https://docs.oracle.com/javase/tutorial/networking/datagrams/index.html</a>
* @see <a href="https://docs.oracle.com/javase/tutorial/essential/io/datastreams.html">https://docs.oracle.com/javase/tutorial/essential/io/datastreams.html</a>
* @see <a href="https://en.wikipedia.org/wiki/User_Datagram_Protocol">https://en.wikipedia.org/wiki/User_Datagram_Protocol</a>
* @author mcgredo
......@@ -17,9 +18,9 @@ import java.net.*;
*/
public class UdpReceiver
{
// private static final int SENDING_PORT = 1414; // port used by UdpSender, unneeded here
private static final int RECEIVING_PORT = 1415;
private static final String DESINATION_HOST = "localhost";
// public static final int SENDING_PORT = 1414; // port used by UdpSender, unneeded here
public static final int RECEIVING_PORT = 1415; // sharable
public static final String DESTINATION_HOST = "localhost";
/**
* Program invocation, execution starts here
......@@ -38,6 +39,7 @@ public class UdpReceiver
udpSocket = new DatagramSocket(RECEIVING_PORT);
udpSocket.setReceiveBufferSize(1500); // how many bytes are in buffer? MTU=1500 is good
udpSocket.setBroadcast(false); // we're just receiving here
// udpSocket.setReuseAddress(true);
byte[] byteArray = new byte[1500];
DatagramPacket receivePacket = new DatagramPacket(byteArray, byteArray.length);
......@@ -58,6 +60,8 @@ public class UdpReceiver
packetCount++; // good practice to increment counter at start of loop, when possible
udpSocket.receive(receivePacket); // blocks until packet is received
System.out.println("UdpReceiver address/port: " + udpSocket.getInetAddress().getHostAddress() + "/" + RECEIVING_PORT);
// values of interest follow. order and types of what was sent must match what you are reading!
firstInt = dis.readInt(); // packetID
secondFloat = dis.readFloat();
......
......@@ -19,13 +19,14 @@ import java.net.*;
*/
public class UdpSender
{
private static final String MY_NAME = System.getProperty("user.name"); // guru incantation 8)
// private static final int SENDING_PORT = 1414; // not needed, can let system choose an open local port
private static final int RECEIVING_PORT = 1415;
private static final int TOTAL_PACKETS_TO_SEND = 100;
public 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
public static final int RECEIVING_PORT = UdpReceiver.RECEIVING_PORT; // 1415; ensure consistent
public static final int TOTAL_PACKETS_TO_SEND = 100;
public static final String DESTINATION_HOST = "localhost";
// here is what we need for lab comms
private 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
// 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
/**
* Program invocation, execution starts here
......@@ -67,6 +68,8 @@ public class UdpSender
InetAddress sourceAddress = InetAddress.getByName("localhost"); // possibly identical if source not modified
DatagramPacket datagramPacket = new DatagramPacket(byteArray, byteArray.length, destinationAddress, RECEIVING_PORT);
System.out.println("UdpSender address/port: " + destinationAddress.getHostAddress() + "/" + RECEIVING_PORT);
// Hmmm, how fast does UDP stream go? Does UDP effectively slow packets down, or does
// this cause network problems? (hint: yes for an unlimited send rate, unlike TCP).
......@@ -100,7 +103,7 @@ public class UdpSender
" sent values(" + packetID + "," + value + ",\"" + message + "\"," + isPacketIdEvenParity +
")" + padding + " as packet #" + index + " of " + TOTAL_PACKETS_TO_SEND);
baos.reset(); // clear the output stream after sending
}
} // end for loop
}
catch (IOException | InterruptedException 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