Solved

In Visual C++, how do I connect to an HTTP server via a firewall.

Posted on 2002-04-04
10
244 Views
Last Modified: 2013-12-14
I am developing Visual C++ software that must be able to connect to its server from behind a firewall.  Can anyone out there explain how to do this for SOCKS4, SOCKS5, and any other types of firewall?  Thanks.
0
Comment
Question by:dmcamens
  • 5
  • 3
  • 2
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6918525
The WinInet functions should handle that transparently by using the local internet settings - AFAIK there's no need to make any special considerations in your program...
0
 

Author Comment

by:dmcamens
ID: 6918701
I have tried to use the WinInet classes and the problem with them is that they do not support asynchronous HTTP requests, as far as I could tell.  The problem with that is that I have to wait for a request to be completely processed before making another one.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6918742
I'm talking about the WinInet API, not the MFC classes that are wrapped around them - 'WSARecv()' and 'WSASend()' both can handle asynchronous requests...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dmcamens
ID: 6918767
How do I get WSARecv and WSASend to allow me to send/recv the requests through a firewall?  Is there another API function to configure the firewall parameters such as the proxy name, port, and protocol?
0
 
LVL 86

Expert Comment

by:jkr
ID: 6918789
>>Is there another API function to configure the firewall
>>parameters such as the proxy name, port, and protocol?

You don't have to - these functions use the local computer's settings. IOW, once you have configured your machine to access the Internet through a firewall, the winsock layer takes care of that. BTW, these are low-level functions operating on sockets. The WinInet API is a bit more high-level, and even withthe MFC wrapper classes you can have requests running asynchronously by using multiple threads...
0
 

Author Comment

by:dmcamens
ID: 6919310
I just tried out the WSA functions.  I am testing it out with WSAAsyncGetHostByName.  I cannot seem to get this to work through a firewall (my machine is configured properly).  When I try to use the MFC classes (see code below), it gets through the firewall but I don't think that I can use multiple threads to make it asynchronous.  I believe I tried that before and the different threads were blocking each other as far as I remember.  Note that I supplied the proxy name into the CInternetSession constructor.  Without that proxy name it does not work.

if (IsDlgButtonChecked(IDC_PROXY_CHECK))
{
    m_proxyEdit.GetWindowText(proxyName);
    dwAccessType = INTERNET_OPEN_TYPE_PROXY;
}
         
iSession = new CInternetSession(
NULL,
1,
dwAccessType,
proxyName.GetBuffer(0),
NULL,
0);                                            
hConnection = iSession->GetHttpConnection(server);
         
pHttpFile = hConnection->OpenRequest("GET",filename.GetBuffer(0));
     
pHttpFile->SendRequest();
nBytes = pHttpFile->Read(httpResponse, 999);
httpResponse[nBytes] = '\0';
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6922170
>>firewall but I don't think that I can use multiple threads to make it asynchronous

Yes you can.  It's pretty straightforward.  For simplicity, create, use, and destroy the session and connection all within the thread proc.  Don't try to pass these objects around unless you want to do extra work.

-- Dan
0
 

Author Comment

by:dmcamens
ID: 6925101
Ok, I see what you mean now.  I was trying to use the same CInternetSession object in each thread to take advantage of the fact that HTTP can keep a session going instead of connecting and disconnecting for each and every request.  That may be a performance hit but we may be able to live with it.  Do you know a way to still take advantage of the "keep alive" functionality?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 200 total points
ID: 6926269
I'm not sure about 'keep alive' I think it has to do with server-side handling.

On the client side, if you never close the session, then the session remains 'live' and you can reuse it to go to the same server again and again with OpenURL() et. al.  

-- Dan
0
 

Author Comment

by:dmcamens
ID: 6926276
Dan,

Thanks for your help.  I think I will go with the multithreading WinInet classes since the prototype I built seems to be working through the firewall now.

Thanks,
-Doug
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Syntax Error 2 91
find Speed using GPS latitude & longitude 4 80
Finding Divisors 5 35
How to add columns to a RAD Studio FMX grid at design time 1 27
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question