Home > Net >  Bosses come and help me c # socket
Bosses come and help me c # socket

Time:04-26

I use c # socket for baidu's web pages, but there is always a variety of problems such as the do
{sl=ss. The Receive (res, off, 1024, 0).
Off +=sl;

} while (sl==1024);
And do
{sl=ss. The Receive (res, off, 1024, 0).
Off +=sl;

} while (ss. Available> 0);
Can obtain the complete web page, probably read 2880 bytes returned,
Do
{sl=ss. The Receive (res, off, 1024, 0).
Off +=sl;

} while (sl> 0);
So we can get to complete web pages but one minute delay, how to get it? Thank you,

CodePudding user response:

Why web processing hard to use the socket? HttpWebRequest WebClient are much stronger than that one

CodePudding user response:

Ss. The Receive (res, off, 1024, 0)
If you can understand his meaning, write their own

He gave 1024 buffer, mean maximum can read 1024, minimum between 0 and 1024

If there are eight apples, take three at a time, ask you what time to take the

3, of course, is to get enough time and he took the

So your decision condition is

Do

While (less than 1024)

CodePudding user response:

Of course as a web page, so you write is not enough,
Because web pages according to the HTTP protocol, you simply put him as byte read not reasonable writing, your to decode HTTP protocol to

So we suggest that, if not don't want to study what is the HTTP protocol, if you not want to study what he make the wheels and blog garden (the so-called do not build the wheels, is not a good programmer series books)
Please use httpclient directly

CodePudding user response:

Read page you with the operation of the socket, is equivalent to, and you want to go to 1000 kilometers of destination, and you choose your transportation to, instead of using the existing public transport, high-speed trains, planes,
Or, do you want to build a house, should buy brick cement line normally, and you to build a brick factory, the equivalent of cement plant, such as
You can first take a look at the socket, TCP, HTTP these concepts, then see httpclient object,

CodePudding user response:

Upstairs said good others building cars with a ready-made synthesis, are you still making wheels

The easiest way to get the data of
 
WebClient wc=new WebClient ();
Wc. Encoding=System. Text.. Encoding UTF8;
The string result=wc. DownloadString (" http://www.baidu.com ");

CodePudding user response:

Upstairs is
Can also be so use
WebClient wc=new WebClient ();
String uri="http://www.baidu.com";
Stream, Stream=wc. OpenRead (uri);
StreamReader sr=new StreamReader (stream);
String strLine="";
While ((strLine=sr. ReadLine ())!=null)
{
Enclosing listBox1. Items. The Add (strLine);
RichTextBox1. AppendText (strLine);
}
The sr. The Close ();

CodePudding user response:

refer to fifth floor big watermelon cut a piece of a kilo of reply:
upstairs said good others building cars with a ready-made synthesis, are you still making wheels

The easiest way to get the data of
 
WebClient wc=new WebClient ();
Wc. Encoding=System. Text.. Encoding UTF8;
The string result=wc. DownloadString (" http://www.baidu.com ");

Thank you, actually I wanted to know how the socket to receive the data, I used c # the webclient inside, it can quickly access web pages, images, etc, but I don't know how the underlying implementation, should also use the socket

CodePudding user response:

refer to 7th floor weixin_57430610 response:
Quote: refer to fifth floor big watermelon cut a piece of a kilo of reply:
upstairs said good others building cars with a ready-made synthesis, are you still making wheels

The easiest way to get the data of
 
WebClient wc=new WebClient ();
Wc. Encoding=System. Text.. Encoding UTF8;
The string result=wc. DownloadString (" http://www.baidu.com ");

Thank you, actually I wanted to know how the socket to receive the data, I used c # the webclient inside, it can quickly access web pages, images, etc, but I don't know how the underlying implementation, should also use the socket


Well, that is to say, you are specially to play wheels,

So I first go to read a book, hey hey, let a person some people think that reading is despised,

But there are some things you don't read a book first, we can't go to say things behind

The HTTP protocol is a text, for example, separate department head part and the body part two pieces of
In most cases the head part length, after you decide whether to receive the judgement is based on the length of the
A few cases the head is not the length, the use of chunked way, not sure the body length, usually have disconnected the server for the standard
Related description
https://blog.csdn.net/yankai0219/article/details/8269922


So if these things you don't go to Chou Chou HTTP protocol, HTTP packets, such as basic data, we can't down

CodePudding user response:

You see, chunked mode of continue keeplive and not keeplive

So if you want to own, generally there is a figure, at the very least you put http1.1 (w3c http1.1 RFC) read through the agreement content to start

CodePudding user response:

The w3c http1.1 RFC

https://www.w3.org/Protocols/rfc2616/rfc2616.html

CodePudding user response:

Is to the underlying protocol processing, interpretation, destruction and so on, the principle is not complicated, but the implementation process is very complex, data block, list, the buffer pool, all kinds of algorithm... Than your car may also build a complex,

CodePudding user response:

Thank you, I go to understand it

CodePudding user response:

Top that haven't been to for a long time
  •  Tags:  
  • C#
  • Related