Gordon Beaton <> wrote:
> On 10 Nov 2003 23:56:27 -0800, Luke Skywalker wrote:
>> My problem is that the lengths are integer coded (by the C program)
>> into the network order (using the htons() and htonl() functions).
> Network byte order is big endian. Use a DataInputstream; it has
> methods to read various data types stored in big endian order.
It is not a coincidence that 'network byte order' happens to coincide with
what Java uses in it's input and output. DataInputStream is the way to go,
and remember that all Java numeric types except char are signed. Java short's
are always 16 bits, int's are always 32 bits and long's are always 64 bits.
If your packet length is stored as a 16 bit value in network byte order, you
coulde read it like so:
try {
DataInputStream din = new DataInputStream(in);
short packetLength = din.readShort();
} catch (IOException ioe) {
// Do something to handle the exception
}
--
Craig West Ph: (416) 666-1645 | It's not a bug,
acwest- | It's a feature...