Search:
Namespaces
Discussions
.NET v1.1
Feedback
NOT ANSWERED: Stream.Read never seems to get all of the data
Messages
Related Types
This message was discovered on
ASPFriends.com 'ngfx-io' list
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Devin Rader
I am tring to perform an HTTP GET using the
TcpClient
and am having
problems. The Read method only seems to actually read a small portion of
what the BufferSize says it is.
TcpClient
t = new
TcpClient
();
t.Connect("www.mysite.com",80);
NetworkStream
nStream = t.GetStream();
string sToSend = "GET /somepage.asp HTTP/1.0\r\n\r\n";
byte[] bData =
Encoding
.ASCII.GetBytes(sToSend.ToCharArray());
nStream.Write( bData,0,bData.Length );
byte[] re = new byte[t.ReceiveBufferSize];
int bS = t.ReceiveBufferSize; <--BufferSize is like 8000
int bytesread = nStream.Read(re,0,t.ReceiveBufferSize); <--bytesread is
liek 450
It only seems to be reading enough to get the page headers and thats it.
Any ideas what I am doing wrong?
Thanks!
Devin
| [ngfx-io] member
Click here to reveal e-mail address
= YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-io.asp
= JOIN/QUIT
Reply to this message...
Mitch Denny (VIP)
Devin,
The Read(...) method can only retrieve data that has actually
arrived, and it is a non-blocking method, so even though you
have said you want to read in 8000 bytes, you only get the
300 or so that are available.
This is a reality of network programming, you need to go
back and get more data from the input buffer from time to
time. If you just want to do a simple get then I would
consder looking at a class like
HttpWebRequest
which works
are a higher level and handles alot of this for you for free.
----------------------------------------
- Mitch Denny
-
Click here to reveal e-mail address
- +61 (414) 610-141
-
-----Original Message-----
From: Devin Rader [mailto:
Click here to reveal e-mail address
]
Sent: Thursday, 2 May 2002 04:13
To: ngfx-io
Subject: [ngfx-io] NOT ANSWERED:
Stream
.Read never seems to get all of
the data
I am tring to perform an HTTP GET using the
TcpClient
and am having
problems. The Read method only seems to actually read a small portion
of what the BufferSize says it is.
TcpClient
t = new
TcpClient
();
t.Connect("www.mysite.com",80);
NetworkStream
nStream = t.GetStream();
string sToSend = "GET /somepage.asp HTTP/1.0\r\n\r\n";
byte[] bData =
Encoding
.ASCII.GetBytes(sToSend.ToCharArray());
nStream.Write( bData,0,bData.Length );
byte[] re = new byte[t.ReceiveBufferSize];
int bS = t.ReceiveBufferSize; <--BufferSize is like 8000
int bytesread = nStream.Read(re,0,t.ReceiveBufferSize); <--bytesread is
liek 450
It only seems to be reading enough to get the page headers and thats it.
Any ideas what I am doing wrong?
Thanks!
Devin
| [ngfx-io] member
Click here to reveal e-mail address
= YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-io.asp
= JOIN/QUIT
| [ngfx-io] member
Click here to reveal e-mail address
= YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-io.asp
= JOIN/QUIT
Reply to this message...
System.IO.Stream
System.Net.HttpWebRequest
System.Net.Sockets.NetworkStream
System.Net.Sockets.TcpClient
System.Text.Encoding
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com