Solved

System.Net.Sockets Read Unknown size of bytes

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

18 Experts available now in Live!

Get 1:1 Help Now