C# - buffer byte array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zeroonea
    New Member
    • Sep 2008
    • 1

    C# - buffer byte array

    hi there,
    i playing around with an async server, i use BeginReceive with byte array to store incoming data, when a "big" data come, a call back receive can not read it all in one time, so i need repeat call back, i want know how to cache all incoming data in byte array? like byte buffer class in java

    searching..., seem they will do: convert a part of data (in byte array) to string and use StringBuilder to store it, append next part in next call back, check a flag in string to know when they received all data.

    But i don't want convert byte stream to string, with byte array i can easily cast, read data from it by using MemoryStream and BinaryReader

    hope you guys can help me out, thanks
  • tatkosmurff
    New Member
    • Sep 2008
    • 5

    #2
    ---- class object variables
    //your data buffer is created here
    byte[] m_byteReadData = new byte[0];


    ----Read data callback
    // data is returned in l_byteReceivedD ata array

    byte[] l_byteTemp = new byte[m_byteReadData. Length];
    m_byteReadData. CopyTo(l_byteTe mp,0);
    m_byteReadData = new byte[l_byteTemp.Leng th + l_byteReceivedD ata.Length];
    l_byteTemp.Copy To(m_byteReadDa ta,0);
    l_byteReceivedD ata.CopyTo(m_by teReadData,l_by teTemp.Length);

    that is just one sample solution you can use Qeue, or Array object...

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      How about a generic? List<byte> or LinkedList<byte > maybe?

      Comment

      Working...