🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18754

Checksum and DatagramPackets...etc

#18754
From: Bill Rooney
Date: Thu, 23 Apr 1998 00:00
53 lines
2358 bytes
    I have a string that I convert into a byte array, then pass it to
CRC32.updata(byte array).
I want to append it to my datagram packet.  The solution I have come up
with is to break the
4 byte long integer that is returned from CRC32 into 4 hexadecimal
chunks.
    Then I should be able to add each byte to my original byte array, at
the end. However, I am
throwing a NumberFormatException when my hex chunk, tempString, starts
with a thru f.
    I have tried using Byte.decode(), and .valueOf(), also with no
success.
    I have also prefixed my tempString with "#" or "0x" -- also with no
success.

    Earlier I had tried taking my original byte array after gettting the
checksum and converting it
to a String, then concatenating my checksum as a String.  I could not
make this work either.

    I am doing this with datagram packets, rather than with TCP, which
takes care of errors for you on a lower level, because this is what our
project requires.

    Can anyone explain a better way to append checksum at the end of
your data packet, or explain how to make the Byte conversions work
consistently?

Here is some of my code:

      crc32.reset();
      crc32.update(data); //this is my original byte array
      checksum = crc32.getValue();
      String crcString = new String(Long.toHexString(checksum) );
      int tempDecimal = 0;
      String tempString;
      for(int j=0; j<4; j++) {  //break the checksum into four hex
numbers
        tempString = new String(crcString.substring(j*2, j*2+2) );
        try {
          data[packetSize+j] = Byte.parseByte(tempString, 16); //data[x]
should be in the range

}
//0 to 255 decimal
        catch(NumberFormatException nfe) {
          frame.addText("that didn't work\n");
        }
      }

Thanks a bunch,
----Bill Rooney
Technical Details
Message-ID: <353FBD5D.B232D72@pitt.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,55f0c2e252bccded,start
X-Google-Attributes: gidf74b3,public
From: Bill Rooney <worst+@pitt.edu>
Subject: Checksum and DatagramPackets...etc
Date: 1998/04/23
Message-ID: <353FBD5D.B232D72@pitt.edu>
X-Deja-AN: 347059057
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0
Reply-To: wor96@bigfoot.com
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language