Solved

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

Posted on 2002-04-04
10
241 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

856 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