Reputation: 51292
What is the best way to check if client has an open port, and if it's forwarded properly?
The app works like this currently:
The goal is to have an the IP + port info saved on the server to be able to give it to other clients. I could try to open a Socket
from server to client and see if it fails, but is there an easier (faster) way to do it?
For example, this site does something like that: http://www.canyouseeme.org/
Upvotes: 2
Views: 4076
Reputation: 48516
No, there isn't.
To check if a connection can be established, you need to try to establish a connection :) Using a Socket
is a sensible way of doing just that.
You could possibly skip this step for some clients, by checking if the machine has a public IP address or a local one. Still, there is the possibility of company firewalls and things like that, so trying to open a connection is the safest way to go.
Using an ICMP echo request (ping) is not an option, because ICMP is a different protocol from TCP (or UDP) that has no concept of a port number. Pinging can be used to determine if an IP address is reachable, but this is of no added value to your case.
Upvotes: 1