2012-03-06 99 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()是一个阻塞呼叫。如果你从未收到任何输入,它将无限期地在那里等待。

相关问题