How to solve the client/server connection issue behind a router?

I wrote two applications, client and server using Visual C++ 2008. When I try to connect them they work fine in LAN network using local IP address like: for the client and for the server.

The problem is that when they connect over the internet, say for example the client is in a city and the server is in another city and both are behind routers they DO NOT connect even I use the public IP.

 What I know is that the router clients all use one public IP to share internet connection, and the router generate  local IPs for them.
I asked many developers but I had no clear answer, they suggest to disable NAT function of the router or put a redirect port. Then I  responded why MSN for example did not need this kind of configuration to work where multiple users can connect under the same public ip behind a router?

If you know a technique, a website, a resource to solve this problem. Please share it with me I'm waiting...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

When you say client/server, in addition to making sure routers are established on both sides of the router connection (assuming a VPN pair since detail not provided), you need to make sure the ports used by client and server traffic are carried across the router connection. Check the routing tables and the filters on your routers as a beginning to troubleshooting. Do make sure you are using a secure connection such as PPTP in connecting the two routers across the Internet.

See below for some resources on the topic:

DNS Troubleshooting made easy:

Building A WCF Router, Part 2:

How to Configure a FREE Hardward PPTP VPN Using a DD-WRT Compatible Router:

Let me know how it goes and provide additional detail if you need additional ideas. Thanks, Eric
If you are behind a router it's the router that has your public IP. But your application is not on the router but on a computer behind it. To deal with such situation you'll need to set up port forwarding on your routing.
Simply put port forwarding is the way to specify path from internet to some computer in local network.
E.g. we can redirect all packets coming to port A on router (i.e. your public IP) to port B on
Using different external ports we can route traffic to different computers inside LAN.
For more details search for info about NAT (network address translation) and port fowarding.
AndyAinscowFreelance programmer / ConsultantCommented:
Is a firewall active and preventing connection ?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

veepwareAuthor Commented:
Thanks for all of you. But I don't want to touch the router (in other words: NO HARDWARE, but if programmatically then no problem). OK let's go one more time with some extra details.

The clients sends a request (command) to the server, the server however is found on another network.

To clarify things, take the example of  Windows Live Messenger: When I install; it I don't need to touch the router or put any forward port from my part. If I can do it programmatically that it is fine. I attached a diagram on how things are going.

I hope things are clear now,  please feel free to request any extra details to solve this issue.

For request-response communication no port forwarding is required since server has address which is visible from outside and routing the response back to client is performed transparently by NAT.
But if you want to use some king of events then your server acts as a client and hence it needs a route to client and this is done by port forwarding.
Do you know the configuration of the two routers? You have to know what is being/not being routed/forwarded between the two routers/firewalls. If no port forwarding is going on, you would not be able to ping internal locations in the other side of the network. Check on the ports you are using to communicate and make sure those ports are open across the routers or you have to evaluate having your client/server conversation talking on different ports.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
veepwareAuthor Commented:
Ericathome, your response help me a lot, Thank you. I accept your answer as a solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.