public static void notifyRunningInstance(int port,String message){
  try {
    LOGGER.info("Notifying already running instance: " + message);
    InetSocketAddress address=new InetSocketAddress(InetAddress.getLoopbackAddress(),port);
    Socket connection=new Socket();
    connection.connect(address,500);
    try (PrintWriter output=new PrintWriter(new OutputStreamWriter(connection.getOutputStream(),"UTF-8"))){
      output.print(message);
    }
   }
 catch (  IOException ex) {
    LOGGER.warning("Error notifying instance: " + ex);
  }
}

public static void notifyRunningInstance ( int port , String message ) { try { LOGGER . info ( "Notifying already running instance: " + message ) ; InetSocketAddress address = new InetSocketAddress ( InetAddress . getLoopbackAddress ( ) , port ) ; Socket connection = new Socket ( ) ; connection . connect ( address , 500 ) ; try ( PrintWriter output = new PrintWriter ( new OutputStreamWriter ( connection . getOutputStream ( ) , "UTF-8" ) ) ) { output . print ( message ) ; } } catch ( IOException ex ) { LOGGER . warning ( "Error notifying instance: " + ex ) ; } }
sends the given message to the given port , where the already running instance should be listening on .
