About Custom Network Protocols
Hi, I'm developing a Server-Client application. So far I've got a custom protocol to accomplish some tasks. The issue is, that I will release the protocol, but I'm using the java DataInput/OutputStreams for this in the server and client, and I know that primitive data in java are different in how they are made (high bits first, or last, don't know exactly), so when I do for example in.readInt() or out.writeInt(), this works perfect if the server AND the client are made in java, but what if in the future, someone wants to create a custom Client in other language, say C++ for example? Will they be able, if I publish the custom protocol I made, to connect easily to my server? If the answer is no, is there some class in java to make the network connection for easy porting? Sorry if I can't explain this better, english isn't my native language
I believe that DataInputStream and DataOutputStream use network byte order (big-endian), which is standard, so there is no need for conversion. Just say in your documentation that you're using network byte order.
But in case I am wrong, you can always write a utility buffer class that converts endianness. It can have a method getBytes(), which returns the buffer contents in an array of bytes of the endianness of your choice.
NIO (java.nio) gives you more control over endianness. There's a good NIO facade that I use for network apps: http://www.x86labs.org/~ron/code/nonblocking2.tgz
> I believe that DataInputStream and DataOutputStream
> use network byte order (big-endian), which is
> standard, so there is no need for conversion. Just
> say in your documentation that you're using network
> byte order.
I just love java :D I googled about Data-I/O-Streams and you're right, they use network byte order. Thanks for the info (didn't knew that there was a standard network byte order)
> NIO (java.nio) gives you more control over
> endianness. There's a good NIO facade that I use for
> network apps:
> http://www.x86labs.org/~ron/code/nonblocking2.tgz
Thanks for that, it might help me to understand better how to use NIO (I have done just a couple of apps with java normal IO, and couldn't digest the NIO documentation on the API :P)