BinaryWriter Unusual hex

391 Views Asked by At

I got some problem transfering Data via the BinaryWriter.

When I try to send

bw.Write(0x1a);
bw.Write(0xf8);
bw.Write(0x05);

It gets in the output to 0x00 - via

Client2Server._mainSock.Send(ms.ToArray());

What is causing this problem?

Greetings

1

There are 1 best solutions below

0
On BEST ANSWER

You are writing 3 integers here. Integers take 4 bytes, and in the cases shown, 3 of them are going to be zeros. Send bytes instead:

bw.Write((byte)0x1a);

of course, if you are writing bytes, then BinaryWriter is overkill - you could just use the Stream.