I'm supposed to send a header in hex format. I was given the following:
The header needs to be in HEX.
The "Chr" represent's a decimal value.
HEADER = Chr(85) & Chr(170) & Chr(0) & Chr(255)
If I prepend the hex value to my socket message, the hex value is FF00AA55. Since hex is not a supported type in java, how should this be transmitted to their server using the Printwriter?
I would say hex is nowhere a type. It's a notation-convention. 0xFF00AA55 is a 4-byte Hexvalue, and might be 4 bytes, a 4-byte Number, a 4-byte Color (transparency, RGB) or an header. I'm not used to Printwriter - looks a bit curious to me in this context.
And the javadocs show me that I'm right:
It does not contain methods for writing raw bytes, for which a program should use unencoded byte streams.
However,
could work.
Are you bound to Printwriter, or may you use another kind of Stream?
See if Integer.toHexString() does what you want. Maybe on a char by char basis.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Warren Dew
blacksmith
Ranch Hand
Joined: Mar 04, 2004
Posts: 1328
posted
0
If you use Java Strings, be sure the other end is expecting unicode rather than ASCII.
One question - when you say "header is supposed to be in hex", do you actually mean it's supposed to be characters representing the number in hexadecimal notation, or is what's really meant that the header is supposed to be in raw binary? If the latter, you'll probably need to convert to bytes and send that.