I have a C# socket server I want to send to my android client my buffer array size with BinaryWriter class. But my client can not read the integer value with readInt method. Can anyone help me where is my wrong?
C# code:
NetworkStream ns = new NetworkStream(socket.socket);
BinaryWriter bw = new BinaryWriter(ns);
bw.Write(message.Length);// message byte[] length 116868
bw.Write(message);
bw.Flush();
bw.Close();
Android code:
DataInputStream inputStream = new DataInputStream(sc.getInputStream());
int len = inputStream.readInt();// readed integer value -851443200
UPDATE My code has a big endian little endian problem. I'm trying to sort byte array on server side but my client sometimes get the correct value and sometimes dont. here is my server side code again:
NetworkStream ns = new NetworkStream(socket.socket);
BinaryWriter bw = new BinaryWriter(ns);
byte[] dataLength = BitConverter.GetBytes(message.Length);
//here i convert little endian to big endian for communucation with the client
Array.Sort(dataLength, 0, dataLength.Length);
bw.Write(dataLength);
bw.Flush();
bw.Close();