Solved

System.Net.Sockets Read Unknown size of bytes

Posted on 2008-06-25
2
858 Views
Last Modified: 2012-05-05
In an application I read data from the System.Net.Sockets.TCPClient buffer, but because I don't know the exact bytes to read I am having problems. The read function fires a timeout. Is there a way to read unknown bytes?
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.ReadTimeout = 20000
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))

Open in new window

0
Comment
Question by:emresamisuzer
[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 Comments
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 100 total points
ID: 21870850
Read(), will return the number of bytes counted, so if you have a return value less than 20000, you have reached the end of the stream.
Also you can check the .DataAvailable property before trying to read.
0
 
LVL 11

Accepted Solution

by:
melmers earned 400 total points
ID: 21872095
When you have an unknown number of bytes you can read them byte per byte from the stream
and add the byte to an array of bytes. when no bytes are on the line then you have reached the end.

The other way is to read the data async with .BeginRecive and .EndRecive when you call .EndRecive
you get the number of readed bytes as a long value.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applicationsā€¦
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a feā€¦

726 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