Socket allows you to establish communication between two machines on a network. There may be several filrewalls along the way:
- personal firewall on both sides
- company firewalls on both sides.
- Internet service provider firewalls on both sides.
Firewalls can be configured to block
- specific IP addresses
- specific ports
- certain protocols
- traffic direction (in / out bound)
In addition, two different situations look the same in terms of TCP:
- server does not listen on port
- the firewall blocks the connection (see above)
Soon you should decide what you want to check. If, for example, you just want to know that you can connect to a specific port on a specific machine call new Socket(host, port) and catch exception. If you want to distinguish between a situation that the firewall bothers you or the remote computer is not responding, this is not enough.
In this case, you will need another link. For example, you know that there is an HTTP server on the remote host, and on another proprietary server that can be blocked by the firewall, you can first establish an HTTP connection (to check that the host is alive), and then try to connect to the socket. If HTTP works and the socket, then probably the firewall is not blocking it.
source share