• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A client Server application using UDP Sockets

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to write a distributed Java application consisting of a client and a server that communicate over a UDP
socket. The client should send a number of random data bytes to the server, and the server should send
back a status code and the calculated Internet checksum for the received data bytes.
How do I do this?
Thanks for your help!
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you'll want to start by familiarizing yourself with:

  • network communications in general and UDP in particular
  • the basics of the Java language
  • network communication in Java, such as the relevant parts of the java.net and java.io packages


  • You'll also want to ShowSomeEffort(←click) and TellTheDetails(←click) of what you tried and what specific problems you had, in order to get the most productive use out of this site.

    Welcome to the Ranch! And good luck!
     
    sopranos mamo
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank a lot bro!!!
    I was able to read UDP sockets and was able to implement it.
    please see the code snippet below, if you have any suggestions let me know
    I did it only for even number of sent bytes

    public static long calculateChecksum(byte[] buf) {
    int length = buf.length;
    if(!(length%2==0))
    {
    System.out.print("The Number of bytes sent is odd!");
    System.exit(0);
    }
    int i = 0;

    long sum = 0;
    long data;


    while (length > 1) {

    data = (((buf[i] << 8) & 0xFF00) | ((buf[i + 1]) & 0xFF));
    sum += data;
    // 1's complement carry bit correction in 16-bits (detecting sign extension)
    if ((sum & 0xFFFF0000) > 0) {
    sum = sum & 0xFFFF;
    sum += 1;
    }

    i += 2;
    length -= 2;
    }
    sum = ~sum;
    sum = sum & 0xFFFF;
    return sum;

    }
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic