Solved

System.Net.Sockets Read Unknown size of bytes

Posted on 2008-06-25
2
844 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Clone Visual studio 2013 solution 5 15
VB.Net - For Loop Error 5 23
Get String split 5 31
Showdialog 8 20
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

9 Experts available now in Live!

Get 1:1 Help Now