ghdfghgfdhg
New Member
I try to check if port 80 is available using the following method :Sockets: Discover port availability using JavaI have a Java application that checks if port 80 is available, if so, it runs a small web server listening on port 80. It works great to detect if another Java application listens on port 80, e.g. if I run my application two times, the second instance will correctly tell me that the port 80 is being used.The problem is that I have WAMP running and listening on port 80, and that if I run my Java application after I started WAMP, it won't tell me that the port 80 is busy. It seems that it only tells me if another Java application uses the port 80.That goes beyond my understanding ... any help is greatly appreciated!Code snippet:\[code\]int port = 80;if(!Connection.isPortAvailable(port)) { logger.info("Port " + port + " is already in use");}// in Connection classpublic static boolean isPortAvailable(int port) { ServerSocket ss = null; DatagramSocket ds = null; try { ss = new ServerSocket(port); ss.setReuseAddress(true); ds = new DatagramSocket(port); ds.setReuseAddress(true); return true; } catch (IOException e) { } finally { if (ds != null) { ds.close(); } if (ss != null) { try { ss.close(); } catch (IOException e) { /* should not be thrown */ } } } return false;}\[/code\]