Skip to content
Snippets Groups Projects
Commit fca7b55d authored by cs2017's avatar cs2017
Browse files

AngelBlank update of Receiver and Sender A

parent 693884e8
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ public class ABEspduReceiverA { ...@@ -21,7 +21,7 @@ public class ABEspduReceiverA {
* somewhat outdated--PDUs can be larger--but this is a reasonable starting point * somewhat outdated--PDUs can be larger--but this is a reasonable starting point
*/ */
public static final int MAX_PDU_SIZE = 8192; public static final int MAX_PDU_SIZE = 8192;
public static final String GROUP = "239.1.2.4"; public static final String GROUP = "239.1.2.3";
public static void main(String args[]) { public static void main(String args[]) {
MulticastSocket socket; MulticastSocket socket;
DatagramPacket packet; DatagramPacket packet;
...@@ -32,10 +32,10 @@ public class ABEspduReceiverA { ...@@ -32,10 +32,10 @@ public class ABEspduReceiverA {
try { try {
// Create TCP Bridge // Create TCP Bridge
System.out.println("Creating Bridge."); System.out.println("Opening Bridge.");
ServerSocket serverSocket = new ServerSocket(2999); ServerSocket serverSocket = new ServerSocket(2999);
Socket clientConnection = serverSocket.accept(); Socket clientConnection = serverSocket.accept();
OutputStream os = clientConnection.getOutputStream(); OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os); PrintStream ps = new PrintStream(os);
...@@ -44,20 +44,21 @@ public class ABEspduReceiverA { ...@@ -44,20 +44,21 @@ public class ABEspduReceiverA {
System.out.println("Bridging Complete."); System.out.println("Bridging Complete.");
// Specify the socket to receive data // Specify the socket to receive data
socket = new MulticastSocket(3100); socket = new MulticastSocket(3000);
socket.setBroadcast(true); socket.setBroadcast(true);
address = InetAddress.getByName(GROUP); address = InetAddress.getByName(GROUP);
socket.joinGroup(address); socket.joinGroup(address);
System.out.println("Joined Group");
// Loop infinitely, receiving datagrams // Loop infinitely, receiving datagrams
while (true) { while (true) {
byte buffer[] = new byte[MAX_PDU_SIZE]; byte buffer[] = new byte[MAX_PDU_SIZE];
packet = new DatagramPacket(buffer, buffer.length); packet = new DatagramPacket(buffer, buffer.length);
socket.receive(packet); socket.receive(packet);
System.out.println("Packet Received");
ps.println(packet); //ps.println(packet);
List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData()); List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData());
System.out.println("Bundle size is " + pduBundle.size()); System.out.println("Bundle size is " + pduBundle.size());
......
...@@ -21,10 +21,10 @@ public class ABEspduSenderA ...@@ -21,10 +21,10 @@ public class ABEspduSenderA
public enum NetworkMode{UNICAST, MULTICAST, BROADCAST}; public enum NetworkMode{UNICAST, MULTICAST, BROADCAST};
/** default multicast group we send on */ /** default multicast group we send on */
public static final String DEFAULT_MULTICAST_GROUP="239.1.2.4"; public static final String DEFAULT_MULTICAST_GROUP="239.1.2.3";
/** Port we send on */ /** Port we send on */
public static final int DIS_DESTINATION_PORT = 3100; public static final int DIS_DESTINATION_PORT = 3000;
/** Possible system properties, passed in via -Dattr=val /** Possible system properties, passed in via -Dattr=val
* networkMode: unicast, broadcast, multicast * networkMode: unicast, broadcast, multicast
...@@ -152,6 +152,14 @@ public static void main(String args[]) ...@@ -152,6 +152,14 @@ public static void main(String args[])
// Loop through sending N ESPDUs // Loop through sending N ESPDUs
try try
{ {
int connectionCount = 0;
//Socket socketTcp = new Socket("localhost", 2998);
ServerSocket serverSocket = new ServerSocket(2999);
//InputStream is = socketTcp.getInputStream();
//InputStreamReader isr = new InputStreamReader(is);
//BufferedReader br = new BufferedReader(isr);
System.out.println("Sending " + NUMBER_TO_SEND + " ESPDU packets to " + destinationIp.toString()); System.out.println("Sending " + NUMBER_TO_SEND + " ESPDU packets to " + destinationIp.toString());
for(int idx = 0; idx < NUMBER_TO_SEND; idx++) for(int idx = 0; idx < NUMBER_TO_SEND; idx++)
{ {
...@@ -233,6 +241,33 @@ public static void main(String args[]) ...@@ -233,6 +241,33 @@ public static void main(String args[])
FirePdu fire = new FirePdu(); FirePdu fire = new FirePdu();
byte[] fireArray = fire.marshal(); byte[] fireArray = fire.marshal();
/**String serverMessage = br.readLine();
System.out.println("The message the client sent was " + serverMessage);
// Print some information locally about the Socket
// connection. This includes the port and IP numbers
// on both sides (the socket pair.)
InetAddress localAddress = socketTcp.getLocalAddress();
InetAddress remoteAddress = socketTcp.getInetAddress();
int localPort = socketTcp.getLocalPort();
int remotePort = socketTcp.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("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " +
remoteAddress.toString() + ", " + remotePort + " ))");
System.out.println("Connection count is: " + connectionCount);**/
// The byte array here is the packet in DIS format. We put that into a // The byte array here is the packet in DIS format. We put that into a
// datagram and send it. // datagram and send it.
byte[] data = baos.toByteArray(); byte[] data = baos.toByteArray();
......
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