套接字和http的奇怪问题

套接字和http的奇怪问题

本文介绍了套接字和http的奇怪问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

当我尝试使用套接字连接到服务器时遇到一个奇怪的问题:当我通过家庭网络进行连接时,它可以工作,但是当我通过学校的公共网络进行连接时,连接失败,这可能是您可能猜到的受监视.
我的代码:

Hi everyone!

I am having a strange problem when I try to connect to a server using a socket: It works when I do it from my home networks but it fails connecting when I do it from my school''s public network which is as you may guess monitored.
My code:

    WSASATA init;
    WSAStartup(MAKEWORD(2,2),&init);
SOCKET s=socket(AF_INET,SOCK_STREAM,0);

info.sin_family=AF_INET;
info.sin_addr.s_addr=inet_addr("209.85.227.147");   //Google''s IP address
info.sin_port=htons(80);
connect(s,(struct sockaddr*)&info,sizeof(info));

send(s,aEnvoyer.c_str(),aEnvoyer.size(),0);
    char resp[20001];
int nbcaractere=recv(serveur,resp,20000,0);
resp[nbcaractere]=''\0'';



其中aEnvoyer是包含有效GET请求的字符串.

学校可能正在阻塞这种插座.我知道那里不使用代理.

所以我的问题是:这段代码有问题吗?
我的第二个问题是:firefox和iexplore使用哪种类型的套接字才能与HTTP服务器通信?

非常感谢.
希望我很清楚,
Alban



Where aEnvoyer is a string containing a valid GET request.

The school may be blocking that kind of socket. I know that proxies are not used there.

So my question is: is this code problematic?
My second question is: What type of socket do firefox and iexplore use in order to communicate with HTTP servers?

Thank you very much.
Hoping I was clear,
Alban

推荐答案




这篇关于套接字和http的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 12:03