Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ socket Network
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 29-Nov-10 8:14am
Comments
Richard MacCutchan at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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!
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 565
1 Maciej Los 319
2 Richard MacCutchan 220
3 BillWoodruff 164
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 29 Nov 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100