views:

50

answers:

1

For some reason, the byte array output of BeginReceive fills up with nulls and then the data.

BeginReceive:

AsyncResult = connectSocket.BeginReceive(RecvBuffer2,
                                          0, RecvBuffer2.Length,
                                          SocketFlags.None,
                                          OnDataRecvCallback, null);

Byte Array declaration:

public static byte[] RecvBuffer2 = new byte[9999];

How to remove the nulls and keep the rest of the data?

+1  A: 

Should be doable with LINQ. Untested, since I don't have Visual Studio available right now, but it should be something like this:

var usefulBuffer = RecvBuffer2.SkipWhile(x => x == 0).ToArray()
Heinzi
This answer worked but I had to Reverse (before and after SkipWhile) the array to make it work. Thank You. Answer accepted!
lesderid