This, as indicated by other posters, to the end.
Java DataInputStream expects data to be big-endian (network byte order). Judging from the Mono documentation (for equivalents such as BinaryWriter ), C # tends to be of little significance (by default for Win32 / x86).
So, when you use the standard class library to change the 32-bit int '1' in bytes, they give different results:
//byte hex values Java: 00 00 00 01 C#: 01 00 00 00
You can change the way ints are written in C #:
private static void WriteInt(Stream stream, int n) { for(int i=3; i>=0; i--) { int shift = i * 8; //bits to shift byte b = (byte) (n >> shift); stream.WriteByte(b); } }
EDIT:
A safer way to do this:
private static void WriteToNetwork(System.IO.BinaryWriter stream, int n) { n = System.Net.IPAddress.HostToNetworkOrder(n); stream.Write(n); }
Mcdowell
source share