Sockets in Java

How to check whether the particular port is in use : Java

When i was working on a WIX, i encountered some issue in installing the application  (REST based webservice), my service is not started and later identified that the port number which i set in the application is already used by another application

To identify whether the port is in use, i used the Socket Class in Java, which is an endpoint for communication between two machines but i used for local machine to validate specified port
public Socket(String host, int port) throws UnknownHostException, IOException

if the host is null it will set the host as loopback address

Default image
Vignesh A Sathiyanantham
AWS Certified developer with 8 years of extensive experience working for Cloud and Datacenter solutions and leading a small team in a lean startup based on Bangalore, India

2 Comments

  1. thank u man it works for me

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.