CAsyncSocket Server - unable to connect using public IP

Hi,
I created a server using CAsyncSocket. I am starting the server using the following code:

m_serverSocket.Create(111);
m_serverSocket.Listen();
(m_serverSocket is a class derived from CAsyncSocket)

then I am connecting to it using CSocket using the following code:

m_clientSocket.Create()
m_clientSocket.Connect("127.0.0.1", 111);
(m_clientSocket is a class derived from CSocket)

It works fine for localhost, but I cant connect to it using my public IP.
The error I am getting is 10060, which is a timeout. It seems my server is never reached from outside.

First thing that came to my mind is the firewall, so I disabled both the windows and the router firewalls with no luck. Also, I am sure of my public IP since I get it directly from my router's interface and I have tried various port numbers, like 3111, 7000, 45111..

Thanks in advance..
I.
InvaderAsked:
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.

jkrCommented:
From where is your client trying to connect? If that machine is in your network behind the router, that should work. If it is from outside the router, that will most likely fail.
0
InvaderAuthor Commented:
Both the server and client are on the same machine. As a matter of fact the code for both is running from the same application. Its just a sample program to test sockets.

Localhost works, since the connection is going from my PC -> my PC.
When I use my public IP though the route should be my PC-> my router -> internet -> my router -> my PC.

You say if its outside my router it will most likely fail. Why ? Isnt supposed my server to be accessible from any computer anywhere provided my firewall allows the incoming connection to that port ?
0
jkrCommented:
Is the server bound to the same IP address the client is trying to connect to?

As for teh "outside" part, the IP addresses you are using behind your router are plain invalid on the internet - it's mostly a 192.168.x.y address, which most networks use.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

InvaderAuthor Commented:
I am not sure I understand what do u mean by 'bound'.

I execute server.Create(port) and I expect the server to be available for all IP addresses my computer has on that 'port'. Apparently I am wrong for my public IP.

client.Connect("192.168.x.y, port) works..
client.Connect("202.87.x.y, port) , which is my public IP, doesnt..

I understand my PC doesnt really have my public IP. My router does. Shouldnt my router though redirect the incoming connection to my pc at the same port. I also tried to create a NAT rule on my router to translate incoming connections of 'port' to 'port' for local. Still no luck..

Also, I run a netstat from dos prompt while attempting the connection. What I see being added is this:

Protocol  |  Local Address      |  Foreign Address    |  State
TCP         |  mypc: some port   |  dsldevice.lan: port  | SYN_SENT

The port on the local address is some random port assigned by my computer, the port on the foreign address is the one I am trying to connect to and consequently the one used by my server. It remains in SYN_SENT state until it times out.


0
InvaderAuthor Commented:
Anyway, maybe I am overcomplicating things. To make it simple:

I want to start a server that is accessible from anywhere, not only from inside my local network.

The question is, do I need to program it differently or since I can connect to it from inside my local network I just need to configure my router properly to gain outside access ?
0
InvaderAuthor Commented:
I found the problem.

The server was fine all along. My mistake was that I was trying to use my external IP from the same computer as the server, creating some kind of loopback. When I tried to connect from another computer outside my network it worked fine.
0

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
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
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.