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. Stream Reading & Multibyte encoding.

Stream Reading & Multibyte encoding.

Scheduled Pinned Locked Moved C#
sysadminquestion
3 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.
  • L Offline
    L Offline
    liRetro
    wrote on last edited by
    #1

    I have a network application that is reading an incomming message. The message should be UTF-8 formatted and could be transfered with garbage. I am currently using the StreamReader and BinReader to read from the stream, but I am unsure if I am using these objects properly. When I use the StreamReader to ReadToEnd() will it stop when it has reached an incomplete character? Will it leave the stream position after these incomplete characters, or will it go past them and just not include them in the results? Assert(this);

    L 1 Reply Last reply
    0
    • L liRetro

      I have a network application that is reading an incomming message. The message should be UTF-8 formatted and could be transfered with garbage. I am currently using the StreamReader and BinReader to read from the stream, but I am unsure if I am using these objects properly. When I use the StreamReader to ReadToEnd() will it stop when it has reached an incomplete character? Will it leave the stream position after these incomplete characters, or will it go past them and just not include them in the results? Assert(this);

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This is from MSDN: ReadToEnd works best when you need to read all the input from the current position to the end of the stream. If more control is needed over how many characters are read from the stream, use the Read(Char[],Int32,Int32) method overload, which generally results in better performance. ReadToEnd assumes that the stream knows when it has reached an end. For interactive protocols, in which the server sends data only when you ask for it and does not close the connection, ReadToEnd might block indefinitely and should be avoided. Note than when using the Read method, it is more efficient to use a buffer that is the same size as the internal buffer of the stream. If the size of the buffer was unspecified when the stream was constructed, its default size is 4 kilobytes (4096 bytes).

      L 1 Reply Last reply
      0
      • L Lost User

        This is from MSDN: ReadToEnd works best when you need to read all the input from the current position to the end of the stream. If more control is needed over how many characters are read from the stream, use the Read(Char[],Int32,Int32) method overload, which generally results in better performance. ReadToEnd assumes that the stream knows when it has reached an end. For interactive protocols, in which the server sends data only when you ask for it and does not close the connection, ReadToEnd might block indefinitely and should be avoided. Note than when using the Read method, it is more efficient to use a buffer that is the same size as the internal buffer of the stream. If the size of the buffer was unspecified when the stream was constructed, its default size is 4 kilobytes (4096 bytes).

        L Offline
        L Offline
        liRetro
        wrote on last edited by
        #3

        Hmm, I'll try changing it to Read. I'm guessing that an incomplete character could cause a block, I guess I'll just have to waste the memory in triple allocation (stream, array, string). It's kind of hard to specify a buffer that is the same size as the stream though since with multibyte I won't know the number of chars that are actually in the stream until it's decoded. Assert(this);

        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