Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. BeginRead Method

BeginRead Method

Scheduled Pinned Locked Moved C#
questiontutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikeyhardingboyo
    wrote on last edited by
    #1

    In the documentation on this method it says i can extract the read data within the callback method? i dont understand how to do this... eg NetworkStream str = (NetworkStream) result.AsyncState; byte[] myReadBuffer = new byte[2048]; int numberOfBytesRead = 0; numberOfBytesRead = str.EndRead(result); it says "To obtain the received data, call the AsyncState method of the IAsyncResult, and extract the buffer contained in the resulting state object" so in my case the IAsyncResult = result and I case the stream state from it but how do i get the data? as theres no method to call?? confused :) mike

    K 1 Reply Last reply
    0
    • M mikeyhardingboyo

      In the documentation on this method it says i can extract the read data within the callback method? i dont understand how to do this... eg NetworkStream str = (NetworkStream) result.AsyncState; byte[] myReadBuffer = new byte[2048]; int numberOfBytesRead = 0; numberOfBytesRead = str.EndRead(result); it says "To obtain the received data, call the AsyncState method of the IAsyncResult, and extract the buffer contained in the resulting state object" so in my case the IAsyncResult = result and I case the stream state from it but how do i get the data? as theres no method to call?? confused :) mike

      K Offline
      K Offline
      kiranprabhu
      wrote on last edited by
      #2

      Create a object which looks something like this class ObjectState { public byte[] myReadBuffer = new byte[2048]; public NetworkStream str = set the network stream object u had created } now when you call beginread call it this way ObjectState state = new ObjectState(); networkstream.BeginRead(state.myReadBuffer, 0, 2048, AsyncCallback method pointer, state) //Pass state object to last parameter of BeginRead. when u endread ObjectState state; state = (objectState) result.AsyncState; int numberOfBytesRead = 0; numberOfBytesRead = str.EndRead(result); now use state.myReadBuffer; //This should contain the data u r looking for

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups