0

I have a java application that runs on some server.

When user accesses this application, it needs to check if port 80 on user's machine is available. Based on the status, it will make some redirection.

My question... is it possible to check from java code if port 80 is busy on the user's machine?

vlcod
  • 229
  • 2
  • 3
  • 13
  • 1
    Could you clarify your requirements for me? When someone hits your server running on a computer you own, you want to go back to the client computer and check if they have port 80 open? Could I ask what is the reason for this requirement? – Michael Lloyd Lee mlk Oct 12 '15 at 10:14
  • Did you check this http://stackoverflow.com/questions/434718/sockets-discover-port-availability-using-java – Techidiot Oct 12 '15 at 10:25

2 Answers2

0

There's no reliable method to check if a remote port is busy. Such behaviour will be a security breach. However, you can check if an HTTP resource is reachable just by requesting it. If unknown, server is supposed to return a 404 HTTP code.

However for local port, just try to open a server listening to this port using a ServerSocket

LoganMzz
  • 1,597
  • 3
  • 18
  • 31
  • May need to be more explicit about port, machine and link. You need to check for port 80 availability on user machine ? But don't understand relation between a local free port (which suggests your trying to **create** a server) and link (which suggests your trying to **reach** a server) – LoganMzz Oct 12 '15 at 10:21
0

You need not check the port on user's machine.Port works in conjunction with URL.If the application has already started on server,the user may need to check if it is able to access the server URL and port.You do not need to have port open on your machine(unless of course the server is in your own local machine).All you need to do is check for firewall or network issues so that the server is accessible.

Kumar Abhinav
  • 6,565
  • 2
  • 24
  • 35