Byte Array Conversion

I'm trying to read data after making a winsock call.  the data I get back is a byte array.  the problem i'm having is the data is mixed data types.  I can't just convert it all to strings as it has integer, byte, string, and float datatypes.  I'm not sure how to go about parsing this byte array to get the data i need.  I beleve the data is chr(0) seperated but the problem is the integer can have a 0 value.  I'm not sure how to tell the two apart in a byte array.  any help would be great

the format is . . .
      Server responds with the following packet:
      (int32)            -1
      (byte)            ASCII 'D' (players response, S2A_PLAYER)
      (byte)            active client count

      for each active client
            (byte)            client number / index
            (string)            player name
            (int32)            client's frag total
            (float32)            client's total time in-game
Who is Participating?
bob_obobConnect With a Mentor Commented:
From your description:
(int32) -1
(byte) ASCII 'D'
(byte) active client count

 (byte) client number / index
 (string) player name
 (int32) client's frag total
 (float32) client's total time in-game

If this is correct, the only place that length varies is each string.  It is probably terminated with a null (char(0)) like you expect, but that's the only part.  the other parts are fixed in size.  You can count the other bytes, and always know whether a zero is a real value or the end of one of the strings.

So you would need to parse the byte array.  First toss out the top two values because you know what they mean.
then get the count.
Using the count, loop through getting the client data:

First, the number, one byte.
then the name, however many bytes it takes to reach the null character (and not including it)
then the two 32-bit numbers.

then repeat the loop, because the next byte will be the next client number/index

good luck with it,
why can you dim it as "any"?
luige34Author Commented:
I don't know what "any" is?  Please explain.
luige34Author Commented:
Oh, any only works with the Declare Statement
luige34Author Commented:
Didn't Answer Question.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.