-
[RESOLVED] Self Test TCP Client Server Connection
Hi,
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
client.GetStream.BeginRead(readBuffer, 0, BYTES_TO_READ, AddressOf doRead, Nothing)
End Sub
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
-
Re: Self Test TCP Client Server Connection
Are you behind a router? Have you forwarded the port?
Are you running any firewalls?
-
Re: Self Test TCP Client Server Connection
The firewall is turned off temporarily.
I am using ADSL2+ Modem.
How to find out whether you forwarded the port?
-
Re: Self Test TCP Client Server Connection
If you dont know if you have, you probably havent. What router have you got?
-
Re: Self Test TCP Client Server Connection
It's Beetel 220BX, ADSL2+ Modem
-
Re: Self Test TCP Client Server Connection
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.
-
Re: Self Test TCP Client Server Connection
Thanks a lot Atheist. :thumb:
I'll just try that and report back about it in this thread.
Pradeep :)
-
Re: Self Test TCP Client Server Connection
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
-
Re: Self Test TCP Client Server Connection
Just use your computers local ip that you find if you run the ipconfig command in the command prompt :)
-
Re: Self Test TCP Client Server Connection
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.
-
Re: Self Test TCP Client Server Connection
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
-
Re: Self Test TCP Client Server Connection
Quote:
Originally Posted by Pradeep1210
That works fine... but I assume it is just equivalent of 127.0.0.1, i.e. connecting locally without thru the internet.
How do you mean? You didnt enter 127.0.0.1 in the port forwarding did you?
Quote:
Originally Posted by Pradeep1210
Will someone be able to connect to my PC thru the internet to my PC with that IP address?
If the port forwarding is setup properly and you're running the server then yes indeed! :thumb:
-
Re: Self Test TCP Client Server Connection
Quote:
Originally Posted by Atheist
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
-
Re: Self Test TCP Client Server Connection
Quote:
Originally Posted by Atheist
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! :thumb:
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
-
Re: Self Test TCP Client Server Connection
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.
-
Re: Self Test TCP Client Server Connection
Quote:
Originally Posted by Pradeep1210
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.
-
Re: Self Test TCP Client Server Connection
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?
-
Re: Self Test TCP Client Server Connection
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.
-
Re: Self Test TCP Client Server Connection
Thanks :D
Seems like that will solve my problem.
Pradeep :)
-
Re: Self Test TCP Client Server Connection
I hope it works out for you :thumb:
-
1 Attachment(s)
Re: Self Test TCP Client Server Connection
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
-
Re: Self Test TCP Client Server Connection
What happens when you try to connect to your server using the external IP?
-
1 Attachment(s)
Re: Self Test TCP Client Server Connection
Quote:
Originally Posted by Atheist
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
.
-
Re: Self Test TCP Client Server Connection
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.?
-
Re: Self Test TCP Client Server Connection
this sounds like a nat traversal problem.
-
Re: Self Test TCP Client Server Connection
q's
you have assigned your "server" a static ip?
you have registered at no-ip or dyndns?
if so try changing the port to 80(if you are running IIS you'll need to turn it off). this will only work if your isp is not blocking port 80.
-
Re: Self Test TCP Client Server Connection
@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
-
Re: Self Test TCP Client Server Connection
I registered at no-ip.com also. But that too seems to be of no help.
-
Re: Self Test TCP Client Server Connection
-
1 Attachment(s)
Re: Self Test TCP Client Server Connection
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?
.
-
1 Attachment(s)
Re: Self Test TCP Client Server Connection
Ahhhh..
finally things moved.
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.
----------------------------------------------------------------------
-
Re: Self Test TCP Client Server Connection
What else could be the problem with my client app? :sick:
-
Re: Self Test TCP Client Server Connection
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?
-
Re: Self Test TCP Client Server Connection
is your client on the same network or is it somewhere on the internet?
-
Re: Self Test TCP Client Server Connection
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
-
Re: Self Test TCP Client Server Connection
somewhere i saw a no hairpin statement.
-
Re: Self Test TCP Client Server Connection
Yes, screenshot in post #30. But I don't know what hairpin means or how to interpret those results. :(
-
Re: Self Test TCP Client Server Connection
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.
-
Re: Self Test TCP Client Server Connection
So how to get over this problem?
-
Re: Self Test TCP Client Server Connection
i answered that. you need to take the client to the outside.