Read binary data from a byte array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robindegen
    New Member
    • Jul 2006
    • 3

    #1

    Read binary data from a byte array

    I'm not sure how to describe this, but i have a socket receiving data.

    handler.BeginRe ceive(state.buf fer, 0, StateObject.Buf ferSize, 0, New AsyncCallback(A ddressOf ReadCallback), state)

    (there's way more code offcourse.. but basicly my byte array buffer gets filled up all the time when a packet is received)

    This data is put in a byte array. But this data is not ascii... it's binary. I need to read different values... similar to IO.BinaryReader .

    So for example i receive this:
    00 4f 61 48 40 00 80 06 67 13 c0 a8 01 64 53 74 .OaH@...g....dS t

    And i need to convert this to ints, floats, singles etc.

    or is there a way to receive this data as stream so i can use io.binaryreader ? that would be even better.
    Last edited by robindegen; Jul 27 '06, 01:26 PM.
  • robindegen
    New Member
    • Jul 2006
    • 3

    #2
    sorry for the double post.. but i couldn't edit mine anymore.. I found some threads on serialization. But the problem is, that the packets dont have a standard size.. i cant use a "struct" as that would be called in c (type in vb i believe). I have to read the first integer, and based on that i can read the rest of the packet (the first integer describes what kind of packet it is, each packetnumber has a different structure)

    Comment

    • robindegen
      New Member
      • Jul 2006
      • 3

      #3
      Ok it has taken me a while but i came up with the following:

      Dim stream As New MemoryStream(st ate.buffer)
      Dim data As New IO.BinaryReader (stream)
      ConWrite(data.R eadInt16)

      The first 2 bytes send are definately 00 02... so readint16 should return 2.. but it returns 512! How is that possible?

      Comment

      Working...