我正在尝试从正在运行的 Runnable 内部调用一个方法。它等待输入字符串,然后根据字符串(字符串充当命令)调用方法并运行其中的内容。
public class App extends Activity implements Runnable {
public void run() {
try {
ServerSocket serverSocket = new ServerSocket(portNum);
while (true) {
Socket client = serverSocket.accept();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String str = in.readLine();
if(str.equals("test")) {
//method call here
}
} catch(Exception e) {
Log.d("App", e.getMessage());
} finally {
client.close();
Log.d("App", "Done.");
}
}
} catch (Exception e) {
Log.d("App", e.getMessage());
}
}