Solved

StreamReader Seems to be Dropping Lines

Posted on 2006-10-25
4
386 Views
Last Modified: 2010-08-05
I am using StreamReader as the basis for an IRC client I am writing. StreamReader is used within a while...loop and listens (on a thread) for the IRC server to send something.

I have verified via mIRC what will be send from the server during a normal command sequence. However, I have found that the last few lines are not coming through the StreamReader in my program. Further, while debugging my program, if I stop execution, I will find that I loose even more lines.

What I think is happening is that I have to do some processing for each line that comes in via the StreamReader. I think I am taking too long to do the processing and the server is sending more data than I am processing.

Questions:

1) Is StreamReader the best way to get data from an IRC server?
2) Does StreamReader buffer the data (and I should not worry about my processing slowing it down)?
3) Is there a way to buffer the input via StreamReader or some other method?

The basic code is as follows:

public void thread_runner()
          {
      while ( (inputLine = reader.ReadLine () ) != null )
            {
                     if (!inputLine.Equals(null))
            {
                   // Determine what kind of message was received
                    if (inputLine.IndexOf("JOIN") != -1)
            // more statements like this follow
If I find that the inputline contains a string I need to process, I fire an event and let this thread continue on. The main GUI thead does the heavy lifting.

Thanks!
Tom
                  {
0
Comment
Question by:oiTomas
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:ostdp
ID: 17821795
1) Is StreamReader the best way to get data from an IRC server?

It should to the job, personally I like working with the actual underlying streams.

2) Does StreamReader buffer the data (and I should not worry about my processing slowing it down)?

That depends on the underlying stream, since this is a network stream the answer is yes, it is buffered.

3) Is there a way to buffer the input via StreamReader or some other method?

Probably a moot point see 2;)

As for missing lines, could it be that your server is not alway sending either a CR+LF or LF as the end of line ? Maybe sometimes its a CR+LF and sometimes an LF .. those kind of inconsistencies aren't unheard of ;)

0
 

Author Comment

by:oiTomas
ID: 17826967
Hey! Thanks for responding!

On #1: I've been kind of learning about IRC programming as I go and Streams seemed like the best choice. Which class or classes did you have in mind for working with the underlying streams?

On#2: I beleive you are correct on this, I've done a bit of research and it tends to point to StreamReader buffering the input.

Re: Missing Lines: I need to check into this. I explore what the server is sending via mIRC which has a debug mode. Using this tool, I have verified that two lines are being send that my program is just not seeing. I'm wondering if my code which checks for NULLs is getting in the way:

     while ( (inputLine = reader.ReadLine () ) != null )
          {
                   if (!inputLine.Equals(null))
0
 
LVL 4

Accepted Solution

by:
ostdp earned 500 total points
ID: 17827280

The checking for null is actually redundent as the while loop takes care of it already.

What stream are you reading with your StreamReader ? Could you post a little more of that code ?

I assume that it is a NetworkStream, and in that case you may have problems with the StreamReader as the NetworkStream blocks the calling thread if nothing is in the buffer. You could have a case where the StreamReader reads a few bytes which do not have a full line in them and as a consequence discards the bytes. I would try using NetworkStream directly and then buffer the data yourself.
0
 

Author Comment

by:oiTomas
ID: 17827419
Well, you got me thinking: What stream am I reading????  Well, I went back and looked at the debug output from the server and found I was missing one very important thing: I needed to sent a MODE command to the server right after joining a room. This initiates the messages I was looking for. Once I did that, the two missing messages appeared!

I also looked up some info in the NetworkStream class and it does look like something that would work better than does the StreamReader.

Thanks very much for getting me pointed in the right direction!

Tom
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to join on ID, with prefix? 15 60
SqlDependency to get update from sql to my c# app 2 41
help with regular expression to search string 6 27
Search an image for an image 3 31
IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question