Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TelnetClient没有收到任何数据_Android_Apache Commons Net - Fatal编程技术网

Android TelnetClient没有收到任何数据

Android TelnetClient没有收到任何数据,android,apache-commons-net,Android,Apache Commons Net,我正在尝试使用Aapche Commons网络库在Android中实现telnet连接。我使用该示例构建了一个异步任务,但似乎根本没有收到任何数据 这是我的AsyncTask的doInBackground: protected Long doInBackground(String... strings) { publishProgress("Connecting to "+target+"\n"); try { Thread reader = new Threa

我正在尝试使用Aapche Commons网络库在Android中实现telnet连接。我使用该示例构建了一个
异步任务
,但似乎根本没有收到任何数据

这是我的
AsyncTask
doInBackground

protected Long doInBackground(String... strings) {
    publishProgress("Connecting to "+target+"\n");

    try {
        Thread reader = new Thread(new Runnable() {
            @Override
            public void run() {
                InputStream in = tc.getInputStream();
                byte[] buff = new byte[1024];
                int r = 0;
                try {
                    do {
                        r = in.read(buff);
                        if (r > 0) {
                            publishProgress("[R] " + new String(buff, 0, r));
                        }
                    } while (r >= 0);
                } catch (Exception e) {
                    publishProgress(e.getClass()+": "+e.getMessage());
                } finally {
                    publishProgress("\n ++++ Disconnecting from thread.\n");
                    try {
                        tc.disconnect();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        tc = new TelnetClient();
        TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false);
        EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false);
        SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true);
        try
        {
            tc.addOptionHandler(ttopt);
            tc.addOptionHandler(echoopt);
            tc.addOptionHandler(gaopt);
        }
        catch (InvalidTelnetOptionException e)
        {
            System.err.println("Error registering option handlers: " + e.getMessage());
        }

        tc.connect(target, port);
        tc.registerNotifHandler(act);

        reader.start();

        reader.join();
    } catch (Exception e) {
        publishProgress(e.getClass()+" "+e.getMessage());
    } finally {
        publishProgress("+++ End of AsyncTask");
    }

    return 0L;
}
我想我复制了示例中的所有代码,但我只得到:

Connecting to 192.168.3.101
negcode=1, optcode=24 (this is from the notifhandler)
+++ Disconnecting from thread
+++ End of AsyncTask
当我在我的笔记本电脑上运行示例代码时,它工作了,我确实像预期的那样从telnet获得了
login


更新如果我在
tc.connect()
之后等待1500毫秒,它确实可以工作。但这是一个相当丑陋的黑客行为。

不要将线程置于异步任务的后台。把代码放进去。

是的,我知道。这是一些从示例中复制代码的实验。我在另一个部分也做了同样的实验。