G
Guest
hi, i'm trying using the tcpClient to get a html file from net, instead of
using WebClient or WebRequest,
the main part of the source code is like this:
private void tcpconnect()
{
tcp=new TcpClient("www.yahoo.com",80);
tcp.NoDelay=false;
tcp.ReceiveTimeout=60000;
tcp.ReceiveBufferSize=25000;
stream = tcp.GetStream();
byte[] send = Encoding.ASCII.GetBytes("GET /index.html HTTP/1.0\r\n\r\n");
stream.Write(send,0,send.Length);
byte[] receive = new byte[tcp.ReceiveBufferSize];
int lastreceive=stream.Read(receive,0,tcp.ReceiveBufferSize);
string str = Encoding.ASCII.GetString(receive,0,tcp.ReceiveBufferSize);
textBox1.Text=str;
tcp.Close();
stream.Close();
}
but the problem is, while i try to run this function, it didn't read all the
html source code for me, but just a part, i try to run twice of the read
method in the function, and it does continue reading for me. I think there
might be some other function which allow us to check whether the html file is
finished loading or not, but i'm dunno which is it and i can't find it
through the msdn library. Is that anyone could help?
Thank for all
using WebClient or WebRequest,
the main part of the source code is like this:
private void tcpconnect()
{
tcp=new TcpClient("www.yahoo.com",80);
tcp.NoDelay=false;
tcp.ReceiveTimeout=60000;
tcp.ReceiveBufferSize=25000;
stream = tcp.GetStream();
byte[] send = Encoding.ASCII.GetBytes("GET /index.html HTTP/1.0\r\n\r\n");
stream.Write(send,0,send.Length);
byte[] receive = new byte[tcp.ReceiveBufferSize];
int lastreceive=stream.Read(receive,0,tcp.ReceiveBufferSize);
string str = Encoding.ASCII.GetString(receive,0,tcp.ReceiveBufferSize);
textBox1.Text=str;
tcp.Close();
stream.Close();
}
but the problem is, while i try to run this function, it didn't read all the
html source code for me, but just a part, i try to run twice of the read
method in the function, and it does continue reading for me. I think there
might be some other function which allow us to check whether the html file is
finished loading or not, but i'm dunno which is it and i can't find it
through the msdn library. Is that anyone could help?
Thank for all