Solved

StreamReader Seems to be Dropping Lines

Posted on 2006-10-25
4
378 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now