Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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';


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
Posted
Comments
Richard MacCutchan 29-Nov-10 15:42pm    
You do not really explain what happens when "it fails". Do you get an error somewhere, and if so what is the value? Does your program crash, do you get an exception, etc.

1. This code is fine. Your school might have a firewall that blocks such requests.
2. HTTP works on TCP as its transport layer, so browsers use the transport layer sockets made available to them by operating system. Which in windows case will be Winsock.
 
Share this answer
 
Thank you for your reply.
Could you tell me how I can use these transport layer sockets?
In fact, I thought that I was already using Winsock. I've searched for that kind of info for a while, I tried some examples but none of them worked. Thanks!
 
Share this answer
 
v2
Hi,

My guess would be that your school is using a transparent caching proxy. If this is the case then you are actually connecting to a proxy server such as squid[^]. Squid can be configured to block fake browser requests by inspecting the browser headers.

I would suggest that you forge ALL of the browser headers[^] and I suspect you will have better success.

Best Wishes,
-David Delaune
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900