Solved

Sockets/TcpClient: Reading with NetworkStream

Posted on 2006-11-18
6
585 Views
Last Modified: 2012-05-05
Hi.

I'm using NetworkStream to read data from the TcpClient, but it returns data in a weird way as aposed to StreamReader. It returns the whole bunch of data, where each line is supposed to be terminated.. StreamReader reads Line1, NetworkStream reads Line1,2,3,4,5,6 and returns those. Do I set up a TextReader to read from the NetworkStream or does that not make any sense to do that.

The problem is my function to handle the parsing of the data can only handle single, and hence only the first line of the whole buffer is being parsed.. data is formatted like:

C,something,something,something...

Output from NetWorkStream looks similar to (_In one read_):

C,something,something,something...
C,something,something,something...
C,something,something,something...
C,something,something,something...
C,something,something,something...

Output from StreamReader (not using async setup):

C,something,something,something...

In one read, then reads again and returns another line.

I'm puzzled.
0
Comment
Question by:valvet
[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
6 Comments
 
LVL 8

Expert Comment

by:Razzie_
ID: 17970952
If I understand correctly, your problem is that the NetworkStream reads all the 6 lines at once, but you only want a single line of C,something,something,something...

To my knowledge, the NetworkStream cannot write one line at a time (it has no ReadLine() method) so if you use Read() it will always return everything.

So if you want a single line to be read, to my best knowledge you will have to use something other than NetworkStream.

HTH,
Razzie


0
 

Author Comment

by:valvet
ID: 17972105
I kinda of figured, and yes you did understand correctly.

Well, I do like the way it's being read with NetworkStream, as it seems to be a bit faster. I'm gonna have to change my parsing function then I suppose.
0
 
LVL 11

Accepted Solution

by:
Expert1701 earned 500 total points
ID: 17973013
> Do I set up a TextReader to read from the NetworkStream or does that not make any sense to do that.

  System.IO.StreamReader reader = new System.IO.StreamReader(networkStream);
  string line = reader.ReadLine();
  while (line != null)
  {
    //Process Line
    //...
    line = reader.ReadLine();
  }
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

627 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