简体   繁体   English

将addProtocolCommandListener与库org.apache.commons.net.telnet.TelnetClient一起使用时,未知源异常

[英]Unknown Source Exception when using addProtocolCommandListener with library org.apache.commons.net.telnet.TelnetClient

I'm using the following library... 我正在使用以下库...

org.apache.commons.net.telnet.TelnetClient;

I have this piece of code which I am using to connect to a server. 我有这段代码用于连接服务器。

import org.apache.commons.net.*;
import org.apache.commons.net.ProtocolCommandListener
import org.apache.commons.net.ftp.FTPSClient
import org.apache.commons.net.telnet.TelnetClient;


String server = "some server";
String result = '';

//Create the telnet client and connect on port 43
TelnetClient telnetClient = new TelnetClient();
telnetClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
telnetClient.connect(server, 43);

When i get to the line with.... 当我排队时...

telnetClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

I get the following exception.... 我得到以下异常。

Caught: java.lang.NullPointerException Disconnected from the target VM, address: '127.0.0.1:3140', transport: 'socket' java.lang.NullPointerException at org.apache.commons.net.SocketClient.addProtocolCommandListener(SocketClient.java:772) at org.apache.commons.net.SocketClient$addProtocolCommandListener.call(Unknown Source) 捕获:java.lang.NullPointerException与目标VM断开连接,地址:'127.0.0.1:3140',传输:'socket'java.lang.NullPointerException,位于org.apache.commons.net.SocketClient.addProtocolCommandListener(SocketClient.java: 772)在org.apache.commons.net.SocketClient $ addProtocolCommandListener.call(未知来源)

Anybody know why I might be getting this exception? 有人知道为什么我可能会收到此异常吗? If I remove the line I don't so the exception is this line. 如果我删除该行,则不会,因此例外是此行。 And if i use the FTPS client i do not have this problem with SFTP from the same library! 如果我使用FTPS客户端,那么同一个库中的SFTP不会出现此问题!

Hi, thanks for responding, here is a simple example of some supported clients in the library, i'm guessing maybe that whois and ftp client do not support the listner !? 嗨,感谢您的答复,这是库中一些受支持的客户端的简单示例,我猜测也许whois和ftp客户端不支持列表器!

   import org.apache.commons.net.*;
   import org.apache.commons.net.ProtocolCommandListener;
   import org.apache.commons.net.ftp.FTPClient;
   import org.apache.commons.net.telnet.TelnetClient;
   import org.apache.commons.net.whois.WhoisClient;
   import java.io.PrintWriter;

   public class WhoisExample
   {
       public static void main(String args[])
       {
           try {
               WhoisClient whoisClient = new WhoisClient();
               whoisClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
           }
           catch(Exception e) {
               System.out.println("whois client exception" + e);
           }

           try {
               TelnetClient telnetClient = new TelnetClient();
               telnetClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
           }
           catch(Exception e) {
               System.out.println("telnet client exception" + e);
           }

           try {
               FTPClient ftpClient = new FTPClient();
               ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

               System.out.println("no ftp client exception here !");
           }
           catch(Exception e)
           {
               System.out.println("ftp client exception" + e);
           }
       }
   }

I logged a bug with Apache commons net and it has been resolved as not a problem. 我使用Apache Commons Net记录了一个错误,该错误已解决为问题。

Basically .....'Some clients don't currently support the ProtocolCommand Listener.' 基本上……..“某些客户端当前不支持ProtocolCommand侦听器。”

You can find out more from the following link.... 您可以从以下链接中找到更多信息。

https://issues.apache.org/jira/browse/NET-608 https://issues.apache.org/jira/browse/NET-608

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入org.apache.commons.net.telnet.TelnetClient; - import org.apache.commons.net.telnet.TelnetClient; 使用org.apache.commons.net.telnet。*与android的问题 - Problem using org.apache.commons.net.telnet.* with android 使用apache-commons-net TelnetClient发送终端命令时如何禁用echo - How to disable echo when sending a terminal command using apache-commons-net TelnetClient 使用org.apache.commons.net.telnet发送telnet命令 - Send telnet commands with org.apache.commons.net.telnet 我无法使用apache-commons-net TelnetClient禁用echo选项 - I can't disable echo option using apache-commons-net TelnetClient 如何使用“ org.apache.commons.net.ftp.FTPClient”解决异常 - How to solve exception with “org.apache.commons.net.ftp.FTPClient” Apache Commons TelnetClient,java的默认超时 - Default timeout for Apache commons TelnetClient, java Telnet Apache Commons NET打印垃圾字符 - Telnet Apache Commons NET Printing Junk Characters 使用org.apache.commons.net.ftp.FTPClient从AsyncTask类登录FTP时出错 - Error when logging into FTP from AsyncTask class using org.apache.commons.net.ftp.FTPClient TelnetClient (Apache Commons Net 3.7.2 API) 已连接 solaris10 但无法加载 ~/.bash_profile - TelnetClient (Apache Commons Net 3.7.2 API) connected solaris10 but can not load ~/.bash_profile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM