Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C++ local proxy on 127.0.0.1

Posted on 2010-09-03
5
Medium Priority
?
661 Views
Last Modified: 2012-05-10
Hi Guys,

I need to create a local listener, almost something like a proxy in C++ on 127.0.0.1 with a predefined port ex. 1234. How would I approach this?

The application needs to listen for any data that gets passed to it from lets say Firefox (configured to proxy 127.0.0.1:1234) and forward that request to another location. Lets say if that request is www.google.com than it redirects it to a local search engine.

I found something in C# and HttpListener but nothing in C++ on how I could achieve this functionality.

Thank you for all your help. Any feedback will be appreciated.
0
Comment
Question by:xNejX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 33600627
You can do this without writing code... just add www.google.com to your local hosts file and set the IP address to be that of your local search engine. This will redirect the call as you require.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 33600637
If you do want to do this as a C++ app you will need to know how to do socket programming. A good place to start is Beej's Guide to Network Programming.

http://www.beej.us/guide/bgnet/
0
 

Author Comment

by:xNejX
ID: 33600700
Thanks for the reply, I want and need to do it as an app. I am looking for a more specific guideline on where to focus on.

Thank you,
0
 
LVL 40

Accepted Solution

by:
evilrix earned 1000 total points
ID: 33600758
>> I am looking for a more specific guideline on where to focus on.
Well the question is, do you have any idea how to write a socket based application? If not this will be non-trivial and guidelines are not really going to help you much, hence my recommendation to look at Beej's.

Once you understand how to open a socket, listen, accept connections, spawn a new thread to handle the connection, read from the socket, decode the protocol (http?) to identify what the requirement is, then (if necessary) spawn a new socket that connects to the destination and then handle the reading from the source socket and writing to the destination socket and vice versa (don't forget the communication is full-duplex) you'll be on your way. Like I said, this is non-trivial.

It might help if you can explain why you want to do this as there may be a better and simpler alternative.
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 1000 total points
ID: 33600779
You migh tfind http://www.codeproject.com/KB/IP/simplehttpproxy.aspx ("A Simple HTTP Proxy with the ACE Library") interesting - the article comes with full source code.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

604 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