I made a server app and a client app from the post in Atheist's signature (TCP client/server connection ).
Then I tried to run both on my machine, as a self test.
However the results were not as expected.
The server runs fine.
The client runs fine when I put IP Address 127.0.0.1, but errors out when I put my actual internet IP address.
VB.NET Code:
Private client As System.Net.Sockets.TcpClient
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
client = New System.Net.Sockets.TcpClient("122.162.75.237", 43001) '<-- Error: SocketException - No connection could be made because the target machine actively refused it 122.162.75.237:43001
The IP address I put there is what I can see myself from many sites like www.whatismyip.com etc.
I also tried a ping on that address and it returns fine.
What could be the reason?
Pradeep
Last edited by Pradeep1210; Nov 18th, 2008 at 02:35 PM.
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
The firewall is turned off temporarily.
I am using ADSL2+ Modem.
How to find out whether you forwarded the port?
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
Have a look at this.
The public IP reported from whatismyip.com isnt your computers external IP, but your routers. When you connect to that IP on that specific port (43001), you must tell the router to forward the connection to your computer. This is why you need to do port forwarding.
I'll just try that and report back about it in this thread.
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
Unfortunately, it requires static IP for port forwarding. I have a connection with dynamic IP. I contacted my ISP and came to know that they charge a hefty amount to provide connections with static IP address
Is there no way to receive incomming connections without that??
I wonder how other applications like yahoo messenger etc. are managing this? They don't require me any configuration.
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
With your other everyday application, you usually are the client that connects to servers out in the world. In this case you're running the server, and so a little configuration needs to be made.
That works fine... but I assume it is just equivalent of 127.0.0.1, i.e. connecting locally without thru the internet.
Will someone be able to connect to my PC thru the internet to my PC with that IP address?
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
With your other everyday application, you usually are the client that connects to servers out in the world. In this case you're running the server, and so a little configuration needs to be made.
Many a times I find my firewall reporting that a particular application is trying to act as server (especially yahoo messenger). They work fine.
Also P2P programs work just fine. How do they manage that thing?
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
How do you mean? You didnt enter 127.0.0.1 in the port forwarding did you?
If the port forwarding is setup properly and you're running the server then yes indeed!
My local IP address is 192.168.1.2.
The client program works fine with my local IP address and 127.0.0.1
It fails only when I want to connect using my extenal IP address. (i.e. 122.162.75.237 at present)
I wanted to give the client program to someone else whom I want to connect to my PC. Then give my external IP address over phone whenever he needs to connect to my PC (since it is a dynamic connection and IP address will change each time)
So I doubt if I'm not able to connect thru my external IP address, he won't be able to connect either.
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
Many applications these days uses TCP to communicate between processes or even within the same process, that might or might not be what is going on when an application is trying to act as a server.
P2P is an whole technology on its own, way to advanced to summarize in one single post
Many large companies have advanced solutions to work around the problem of port forwarding. Skype for example uses intermediate "master-servers" to allow one person to initiate a connection with someone else.
Though you'll find that port forwarding is still needed. The BitTorrent technology for example requires port forwarding for maximum efficiency. Setting up a private dedicated server in CSS also requires port forwarding.
My local IP address is 192.168.1.2.
The client program works fine with my local IP address and 127.0.0.1
It fails only when I want to connect using my extenal IP address. (i.e. 122.162.75.237 at present)
I wanted to give the client program to someone else whom I want to connect to my PC. Then give my external IP address over phone whenever he needs to connect to my PC (since it is a dynamic connection and IP address will change each time)
So I doubt if I'm not able to connect thru my external IP address, he won't be able to connect either.
Pradeep
Thats right. But by fowarding the port 43001 to your local IP, the router will forward any incoming traffic to your computer, as long as your local IP stays the same.
But the local IP as well as the external IP changes everytime the modem is reset.
What should I do?
Is there some way to setup peer to peer connection since client-server is not exactly what I require. And will that get me rid of that port forwarding setup?
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
The external IP changing is, as you've found, nothing you can do anything about unless you pay your ISP a rude amount of money. You could use no-ip.com to give your external IP a static hostname.
Making your local IP static is not hard, read this.
Peer to peer isnt as "peer-to-peer" as it sounds, you still have to have one host listening for a connection and one host actively connecting to the listening host. Creating a pure peer to peer network defenitely isnt an easy task.
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
I assigned a fixed local IP address and then configured my router for port forwarding with local IP address.
But still I can access it using the local IP or 127.0.0.1 but not with my external IP address.
So the problem is still the same. How should I let the anyone connect to my PC thru the internet?
Please have a look at the screenshot. Maybe I have messed up something. I had assigned static local IP address 192.168.1.11
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
What happens when you try to connect to your server using the external IP?
I get the same error I was getting before.
"No connection could be made because the target machine actively refused it"
But there is no error if I replace the IP address with 192.168.1.11 or 127.0.0.1
.
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
Very odd. Have you tried resetting your router? It should forward the connection to your computer. I take it you've doublechecked everything; the external IP you're trying to connect to, the local IP you supplied in the router, etc.?
@Atheist:
I have resetted the router many times and put the new external IP address. The error is same everytime. I just resetted the router again to confirm and the new IP address I got is 122.162.75.13. This too fails with the same error.
@dbasnett
I have assigned static local IP address in system settings only. No changes in code.
This is how the server code goes (credits Atheist):
vb Code:
Public Sub New()
listener = New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, 43001) 'The TcpListener will listen for incoming connections at port 43001
listener.Start() 'Start listening.
listenThread = New System.Threading.Thread(AddressOf DoListen) 'This thread will run the doListen method
listenThread.IsBackground = True 'Since we dont want this thread to keep on running after the application closes, we set isBackground to true.
listenThread.Start() 'Start executing doListen on the worker thread.
RaiseEvent ServerStarted(43001)
End Sub
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
I registered at no-ip.com also. But that too seems to be of no help.
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
I downloaded a NAT tester from a link in that wikipedia article. It gives the result as in the screenshot, but then crashes.
Could this information be of any help?
.
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
I got this error on my server application in the ConnectedClient class when I tried to probe the port from https://www.grc.com/x/portprobe=43001 I'm not much concerned about the error since that website might have done something wierd.
But this confirms that the port is now open to the internet but for some reason or the other my client application is not able to connect to it.
Here is the result of port probe:
Code:
----------------------------------------------------------------------
GRC Port Authority Report created on UTC: 2008-11-20 at 01:01:44
Results from probe of port: 43001
1 Ports Open
0 Ports Closed
0 Ports Stealth
---------------------
1 Ports Tested
THE PORT tested was found to be: OPEN.
TruStealth: FAILED - NOT all tested ports were STEALTH,
- NO unsolicited packets were received,
- A PING REPLY (ICMP Echo) WAS RECEIVED.
----------------------------------------------------------------------
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
What else could be the problem with my client app?
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
Are you still completely unable to connect using the external IP? What about the last screenshot you posted, was that when you connected using the local ip?
I'm not having any issues using the local IP address or the localhost (127.0.0.1) ever since the beginning.
I can't connect using the external IP, but port probe from various internet based software tell me that the port 43001 is open on my system. The screenshot I posted in the last is what I still get when trying to probe that port. That confirms that port is open. So what is the reason I can't connect using the external IP address using the TCPClient class?
The client and server are on same machine (for testing).
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
Yes, screenshot in post #30. But I don't know what hairpin means or how to interpret those results.
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
that would be a hairpin(client / server on same machine). that is the first time i have seen it used in this context. i knew it from SONET and it was defined as the ability to send a signal from one drop port to another drop port without accessing the network.
you need someone on the outside to connect to your port.
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering