RDT Project Implement Checksum, Ack












0















I need to implement reliable data transfer using checksums, ACKs, sequence numbers and countdown timers and implement the following functions.



  public static int compute_checksum(String message) {}

public static boolean isCorrupt(rdtPacket packet) {}

public static boolean isACK(rdtPacket packet) {}

public static boolean inOrder(rdtPacket packet, int seqno) {} // has_seq()


And add a countdown timer to the socket when waiting for ACKs.



Additionally, the packet format will be:



message checksum sequence number



Finally, ACKs will be sent using the message "ACK"



This is what I have so far:



import java.io.*;
import java.net.*;

class RDTClient {
private static DatagramSocket clientSocket;
private static InetAddress IPAddress;
private static final int serverPort = 9876;

public static void main(String args) throws Exception {
try {
String serverHostname = new String("127.0.0.1");

if (args.length > 0) {
serverHostname = args[0];
}

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));

clientSocket = new DatagramSocket();

IPAddress = InetAddress.getByName(serverHostname);
System.out.println("Attemping to connect to " + IPAddress + ") via UDP port " + serverPort);

System.out.print("Enter Message: ");
String message = inFromUser.readLine();

rdt_send(message);

// String response = rdt_rcv();
// System.out.println("Received response: " + response);

clientSocket.close();
} catch (UnknownHostException ex) {
System.err.println(ex);
} catch (IOException ex) {
System.err.println(ex);
}
}

private static String make_pkt(String message) {
System.out.println("[RDTClient:make_pkt] " + message);
return message;
}

private static void rdt_send(String message) {
System.out.println("[RDTClient:rdt_send] " + message);
String packet = make_pkt(message);
udt_send(packet);
}

private static void udt_send(String message) {
// compute the message checksum and create the segment rdt_send and make_pkt
try {
byte sendData = new byte[1024];
sendData = message.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, serverPort);
clientSocket.send(sendPacket);
System.out.println("[RDTClient:udt_send] Message sent");
} catch (IOException ioe) {
System.out.println("Failed to send");
}
}

private static String rdt_rcv() {
try {
byte receiveData = new byte[1024];
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
clientSocket.setSoTimeout(10000);
clientSocket.receive(receivePacket);
String message = new String(receivePacket.getData());
IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();

System.out.println("[RDTClient:rdt_rcv] Received packet from: " + IPAddress + ":" + port);
return message;
} catch (IOException ioe) {
System.out.println("Failed to read from port");
}
return "";
}
}









share|improve this question



























    0















    I need to implement reliable data transfer using checksums, ACKs, sequence numbers and countdown timers and implement the following functions.



      public static int compute_checksum(String message) {}

    public static boolean isCorrupt(rdtPacket packet) {}

    public static boolean isACK(rdtPacket packet) {}

    public static boolean inOrder(rdtPacket packet, int seqno) {} // has_seq()


    And add a countdown timer to the socket when waiting for ACKs.



    Additionally, the packet format will be:



    message checksum sequence number



    Finally, ACKs will be sent using the message "ACK"



    This is what I have so far:



    import java.io.*;
    import java.net.*;

    class RDTClient {
    private static DatagramSocket clientSocket;
    private static InetAddress IPAddress;
    private static final int serverPort = 9876;

    public static void main(String args) throws Exception {
    try {
    String serverHostname = new String("127.0.0.1");

    if (args.length > 0) {
    serverHostname = args[0];
    }

    BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));

    clientSocket = new DatagramSocket();

    IPAddress = InetAddress.getByName(serverHostname);
    System.out.println("Attemping to connect to " + IPAddress + ") via UDP port " + serverPort);

    System.out.print("Enter Message: ");
    String message = inFromUser.readLine();

    rdt_send(message);

    // String response = rdt_rcv();
    // System.out.println("Received response: " + response);

    clientSocket.close();
    } catch (UnknownHostException ex) {
    System.err.println(ex);
    } catch (IOException ex) {
    System.err.println(ex);
    }
    }

    private static String make_pkt(String message) {
    System.out.println("[RDTClient:make_pkt] " + message);
    return message;
    }

    private static void rdt_send(String message) {
    System.out.println("[RDTClient:rdt_send] " + message);
    String packet = make_pkt(message);
    udt_send(packet);
    }

    private static void udt_send(String message) {
    // compute the message checksum and create the segment rdt_send and make_pkt
    try {
    byte sendData = new byte[1024];
    sendData = message.getBytes();
    DatagramPacket sendPacket =
    new DatagramPacket(sendData, sendData.length, IPAddress, serverPort);
    clientSocket.send(sendPacket);
    System.out.println("[RDTClient:udt_send] Message sent");
    } catch (IOException ioe) {
    System.out.println("Failed to send");
    }
    }

    private static String rdt_rcv() {
    try {
    byte receiveData = new byte[1024];
    DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
    clientSocket.setSoTimeout(10000);
    clientSocket.receive(receivePacket);
    String message = new String(receivePacket.getData());
    IPAddress = receivePacket.getAddress();
    int port = receivePacket.getPort();

    System.out.println("[RDTClient:rdt_rcv] Received packet from: " + IPAddress + ":" + port);
    return message;
    } catch (IOException ioe) {
    System.out.println("Failed to read from port");
    }
    return "";
    }
    }









    share|improve this question

























      0












      0








      0








      I need to implement reliable data transfer using checksums, ACKs, sequence numbers and countdown timers and implement the following functions.



        public static int compute_checksum(String message) {}

      public static boolean isCorrupt(rdtPacket packet) {}

      public static boolean isACK(rdtPacket packet) {}

      public static boolean inOrder(rdtPacket packet, int seqno) {} // has_seq()


      And add a countdown timer to the socket when waiting for ACKs.



      Additionally, the packet format will be:



      message checksum sequence number



      Finally, ACKs will be sent using the message "ACK"



      This is what I have so far:



      import java.io.*;
      import java.net.*;

      class RDTClient {
      private static DatagramSocket clientSocket;
      private static InetAddress IPAddress;
      private static final int serverPort = 9876;

      public static void main(String args) throws Exception {
      try {
      String serverHostname = new String("127.0.0.1");

      if (args.length > 0) {
      serverHostname = args[0];
      }

      BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));

      clientSocket = new DatagramSocket();

      IPAddress = InetAddress.getByName(serverHostname);
      System.out.println("Attemping to connect to " + IPAddress + ") via UDP port " + serverPort);

      System.out.print("Enter Message: ");
      String message = inFromUser.readLine();

      rdt_send(message);

      // String response = rdt_rcv();
      // System.out.println("Received response: " + response);

      clientSocket.close();
      } catch (UnknownHostException ex) {
      System.err.println(ex);
      } catch (IOException ex) {
      System.err.println(ex);
      }
      }

      private static String make_pkt(String message) {
      System.out.println("[RDTClient:make_pkt] " + message);
      return message;
      }

      private static void rdt_send(String message) {
      System.out.println("[RDTClient:rdt_send] " + message);
      String packet = make_pkt(message);
      udt_send(packet);
      }

      private static void udt_send(String message) {
      // compute the message checksum and create the segment rdt_send and make_pkt
      try {
      byte sendData = new byte[1024];
      sendData = message.getBytes();
      DatagramPacket sendPacket =
      new DatagramPacket(sendData, sendData.length, IPAddress, serverPort);
      clientSocket.send(sendPacket);
      System.out.println("[RDTClient:udt_send] Message sent");
      } catch (IOException ioe) {
      System.out.println("Failed to send");
      }
      }

      private static String rdt_rcv() {
      try {
      byte receiveData = new byte[1024];
      DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
      clientSocket.setSoTimeout(10000);
      clientSocket.receive(receivePacket);
      String message = new String(receivePacket.getData());
      IPAddress = receivePacket.getAddress();
      int port = receivePacket.getPort();

      System.out.println("[RDTClient:rdt_rcv] Received packet from: " + IPAddress + ":" + port);
      return message;
      } catch (IOException ioe) {
      System.out.println("Failed to read from port");
      }
      return "";
      }
      }









      share|improve this question














      I need to implement reliable data transfer using checksums, ACKs, sequence numbers and countdown timers and implement the following functions.



        public static int compute_checksum(String message) {}

      public static boolean isCorrupt(rdtPacket packet) {}

      public static boolean isACK(rdtPacket packet) {}

      public static boolean inOrder(rdtPacket packet, int seqno) {} // has_seq()


      And add a countdown timer to the socket when waiting for ACKs.



      Additionally, the packet format will be:



      message checksum sequence number



      Finally, ACKs will be sent using the message "ACK"



      This is what I have so far:



      import java.io.*;
      import java.net.*;

      class RDTClient {
      private static DatagramSocket clientSocket;
      private static InetAddress IPAddress;
      private static final int serverPort = 9876;

      public static void main(String args) throws Exception {
      try {
      String serverHostname = new String("127.0.0.1");

      if (args.length > 0) {
      serverHostname = args[0];
      }

      BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));

      clientSocket = new DatagramSocket();

      IPAddress = InetAddress.getByName(serverHostname);
      System.out.println("Attemping to connect to " + IPAddress + ") via UDP port " + serverPort);

      System.out.print("Enter Message: ");
      String message = inFromUser.readLine();

      rdt_send(message);

      // String response = rdt_rcv();
      // System.out.println("Received response: " + response);

      clientSocket.close();
      } catch (UnknownHostException ex) {
      System.err.println(ex);
      } catch (IOException ex) {
      System.err.println(ex);
      }
      }

      private static String make_pkt(String message) {
      System.out.println("[RDTClient:make_pkt] " + message);
      return message;
      }

      private static void rdt_send(String message) {
      System.out.println("[RDTClient:rdt_send] " + message);
      String packet = make_pkt(message);
      udt_send(packet);
      }

      private static void udt_send(String message) {
      // compute the message checksum and create the segment rdt_send and make_pkt
      try {
      byte sendData = new byte[1024];
      sendData = message.getBytes();
      DatagramPacket sendPacket =
      new DatagramPacket(sendData, sendData.length, IPAddress, serverPort);
      clientSocket.send(sendPacket);
      System.out.println("[RDTClient:udt_send] Message sent");
      } catch (IOException ioe) {
      System.out.println("Failed to send");
      }
      }

      private static String rdt_rcv() {
      try {
      byte receiveData = new byte[1024];
      DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
      clientSocket.setSoTimeout(10000);
      clientSocket.receive(receivePacket);
      String message = new String(receivePacket.getData());
      IPAddress = receivePacket.getAddress();
      int port = receivePacket.getPort();

      System.out.println("[RDTClient:rdt_rcv] Received packet from: " + IPAddress + ":" + port);
      return message;
      } catch (IOException ioe) {
      System.out.println("Failed to read from port");
      }
      return "";
      }
      }






      java checksum transfer ack






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 1:20









      MannieMannie

      11




      11
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422652%2frdt-project-implement-checksum-ack%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422652%2frdt-project-implement-checksum-ack%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          SQL update select statement

          'app-layout' is not a known element: how to share Component with different Modules