Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

StreamReader Seems to be Dropping Lines

Posted on 2006-10-25
4
Medium Priority
?
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

610 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