Skip to content

Problems with ReadByte on a TCP/IP Client Stream

David

Asked Mar 6, 2008, 8:10 AM EST2 answers
Share
LinkedInX

Hello,

   Does anyone have any experience using the ReadByte method on a TCP/IP client stream? The method does not return a -1 when I am at the end of a stream, the code just hangs.

Regards,

 Dave

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    While I don't have much experience doing any sort of TCP/IP coding, does the code generate an exception?? if so you can use a try-catch block to catch it as the end of stream. It should throw an InvalidOperationException if you tried to read past the end of the stream.
    0
  • 0

    Hello,

       Thanks for getting back to me. You are correct, using a try,catch block will work, but it is a "work around" for the problem. I am disappointed when thsings do not work as documented. In theory, if there is nothing in the stream you should receive a -1, otherwise you get the char from the stream.

     However, in the real world if there is nothing in the stream you get a exception, which requires you to use a try,catch block as a work around. Well, at leastI have found a way to get the code to work and I can move on to other things that my code needs to do.

    Regards,

    Dave

    0