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
Solved

System.Net.Sockets Read Unknown size of bytes

Posted on 2008-06-25
2
856 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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