2012-03-06 98 views
-4

任何想法爲什麼在執行sendTCPBytes1到localhost之後,system.exit(0)沒有得到執行?Java - 爲什麼system.exit(0)沒有得到執行?

public static void killerButton() throws IOException { 
    String myCmd;   
    if (C.getOs().equals("Linux")) { 
    } else {  
     System.out.println("[bug]: forceclose"); 
     sendTCPBytes1("forceclose", "localhost"); 

     System.exit(0); 
    } 
    } 


    public static void sendTCPBytes1(String filmfr2, String localhost) throws IOException { 
    String downloaded = null; 
    Socket socket = new Socket(localhost, 58888); 
    DataOutputStream upload = new DataOutputStream(socket.getOutputStream()); 
    BufferedReader download = new BufferedReader(new InputStreamReader(socket.getInputStream())); 
    String c = filmfr2; 
    upload.writeBytes(c); 
    upload.flush(); 
    String get; 
    downloaded = download.readLine(); 
    System.out.println("[TCP]: FROM server: >>> " + downloaded); 
    socket.close(); 
} 
+1

此代碼沒有意義。什麼是'C'? 「killerButton」從哪裏來的? – Jivings 2012-03-06 13:54:56

+1

取而代之的是什麼? – oers 2012-03-06 13:55:14

+1

你怎麼知道它沒有被調用? – Nishant 2012-03-06 13:55:18

回答

1

如果您的套接字連接失敗,例如拋出一個IOException,System.exit(0)將不會被調用。

1

假設這種方式實際上按我認爲的方式工作,readLine()是一個阻塞呼叫。如果你從未收到任何輸入,它將無限期地在那裏等待。

相關問題