2016-11-03 11 views
0

私は、各データグラムソケット上で動作する半径サーバのリストを持っており、これらの起動済み半径サーバのリストを私に提供しています。 特定のサーバーが停止しているかどうかを確認し、停止した場合は再起動する必要があるという要件があります。 以下は私が書いているコードですが、これが正しい方法であるかどうかは分かりません。 アドバイスをお願いします。データグラムポートでアプリケーションが実行されているかどうかを確認するにはどうすればいいですか?

....

int port = radiusServer.getAggregation() 
         .getAuthenticationPort(); 
       try { 
        // It will throw IO exception if no application is 
        // running 
        // on that 
        // port. 
        new DatagramSocket(port); 
        LOGGER.info(
          "There is a server running on the Port number {}.", 
          port); 
       } catch (IOException e) { 
        LOGGER.error(
          "Server is not running on port number {}.", 
          port); 
        startServer(radiusServer); 
       } 

....

+0

{しようと{ \t \t \t \t \t \tは//これは、IO例外がスローされますよう \t上 \t \t \t \t \t \t // \t \t \t \t \t //ポート。 \t \t \t \t \t \tたDatagramSocket DS =新規のDatagramSocket(ポート)。 \t \t \t \t \t \t ds.close(); \t \t \t \t \t \t LOGGER.warn( \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t、ポートを "サーバーは、サーバーを開始ポート番号{}で実行されていません。")。 \t \t \t \t \t \t startServer(radiusServer); \t \t \t \t \t}キャッチ(IOExceptionを電子){ \t \t \t \t \t \t(LOGGER.isDebugEnabled()){ \t \t \t \t \t \t \t LOGGER.debug( \t \t \t \t \t \t \t \t場合\t "Porですでに実行されているサーバーがありますt番号{}。」 \t \t \t \t \t \t \t \t \tポート); \t \t \t \t \t \t} \t \t \t \t \t}} – Mohit

答えて

0

以下のソリューションが正常に動作します。何のアプリケーションが実行されている \t \t \t \t \t \t //がない場合

  try { 
        // It wont throw IO exception if no application is 
        // running 
        // on that 
        // port. 
        DatagramSocket ds = new DatagramSocket(port); 
        ds.close(); 
        LOGGER.warn(
          "Server is not running on port number {}. Starting Server", 
          port); 
        startServer(radiusServer); 
       } catch (IOException e) { 
        if (LOGGER.isDebugEnabled()) { 
         LOGGER.debug(
           "There is a server already running on the Port number {}.", 
           port); 
        } 
       } 
関連する問題