Java Implementing htonl
Posted
by Hamza Yerlikaya
on Stack Overflow
See other posts from Stack Overflow
or by Hamza Yerlikaya
Published on 2010-04-20T14:32:51Z
Indexed on
2010/04/20
14:53 UTC
Read the original article
Hit count: 566
java
I am communicating with a server, each message sent to the server has to be padded with the length of the message,
unsigned int len = htonl(msg.size());
In C running the length through htonl and padding the message works, in Java AFAIK byte order is already in network order so I assumed all I have to do is write the string length before the message to the stream, but this does not work am I missing something?
stream.write(msg.length());
stream.write(msg.getBytes());
Stream is an OutputStream.
© Stack Overflow or respective owner