0
試圖瞭解WINSOCKET的使用Visual C++ 在這裏,我的代碼工作:Winsocket的RESV緩衝區錯誤
while (true) {
char l[1];
recv(tsock.sock, l, 1, 0);
std::cout << l << std::endl;
if (!l)
{
return;
}
}
但我有試着時候才能google.com:80 HTTP GET查詢:
Connected
Sending request to host
H╠╠╠╠╠╠╠╠
T╠╠╠╠╠╠╠╠☺
T╠╠╠╠╠╠╠╠☻
P╠╠╠╠╠╠╠╠♥
/╠╠╠╠╠╠╠╠♦
1╠╠╠╠╠╠╠╠♣
.╠╠╠╠╠╠╠╠♠
0╠╠╠╠╠╠╠╠
╠╠╠╠╠╠╠╠
3╠╠╠╠╠╠╠╠
0╠╠╠╠╠╠╠╠
2╠╠╠╠╠╠╠╠♂
╠╠╠╠╠╠╠╠♀
F╠╠╠╠╠╠╠╠
o╠╠╠╠╠╠╠╠♫
u╠╠╠╠╠╠╠╠☼
n╠╠╠╠╠╠╠╠►
d╠╠╠╠╠╠╠╠◄
╠╠╠╠╠╠╠╠↕
╠╠╠╠╠╠╠╠‼
C╠╠╠╠╠╠╠╠¶
...
有很多垃圾收回。但是,當我將緩衝區窗體1單元格的聲明更改爲2以及更多所有內容似乎都是蜂窩工作的時候。 代碼
while (true) {
char l[2];
memset(&l, 0, sizeof(l));
recv(tsock.sock, l, 1, 0);
std::cout << l << std::endl;
if (!l)
{
return;
}
}
而且結果:
ConnectedSending request to hostHTTP/1.0 302 Found
Cache - Control: private
Content - Type : text/html; charset = UTF - 8
Location: http ://www.google.ru/?gfe_rd=cr&ei=r_RPU4yzJ8GdwAOWjoDoAQ
Content - Length : 258
Date : Thu, 17 Apr 2014 15 : 35 : 11 GMT
Server : GFE/2.0
Alternate - Protocol : 80 : quic
<HTML><HEAD><meta http - equiv = "content-type" content = "text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF = "http://www.google.ru/?gfe_rd=cr&ei=r_RPU4yzJ8GdwAOWjoDoAQ">here</A>
.
</BODY></HTML>
什麼這個東西的交易?
爲什麼在每個字符之後刷新流緩衝區? 不會std :: cout << l <<'\ n'好多了嗎? – jcoder