2016-12-27 22 views
0
나는 다음과 같은 라이브러리를 사용하고

와 addProtocolCommandListener를 사용하여 ...알 수없는 소스 예외 라이브러리 org.apache.commons.net.telnet.TelnetClient

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

난에 사용하고이 코드 조각이 서버에 연결하십시오.

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); 

내가 함께 .... 나는 다음과 같은 예외가

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

.... 겁에 질린

라인에 도착하면 : 대상에서 java.lang.NullPointerException이 이 끊김 VM, 주소 : '127.0.0.1:3140', 전송 : 'socket' java.lang.NullPointerException at org.apache.commons.net.SocketClient.addProtocolCommandListener (SocketClient.java:772) at org.apache.c ommons.net.SocketClient $ addProtocolCommandListener.call (알 수없는 소스)

아무 이유없이이 예외가 표시 될 수 있습니다. 줄을 제거하면 예외가 없습니다. 그리고 FTPS 클라이언트를 사용하면 동일한 라이브러리의 SFTP에이 문제가 없습니다!

안녕하십니까, 응답 주셔서 감사합니다. 여기 도서관에서 지원되는 클라이언트의 간단한 예가 있습니다. 어쩌면 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); 
      } 
     } 
    } 
+0

안녕하세요, 나는 질문이? JRE 또는 JDK를 사용하고 있습니까? JRE 나 Ant를 사용하고 디버그 매개 변수를 false로 설정하면 메시지 "Unkonw code"가 표시됩니다. 변경하면 더 많은 정보를 얻을 수 있습니다. 반면에 _NullPointerException_은 telnetClient가 null임을 나타냅니다. 전체 스택 추적을 게시하거나 실제 코드를 완성 할 수 있습니까? 건배 – sdsc81

+0

그래서 다음 코드는 라이브러리에 의해 지원되는 3 가지 다른 예제를 보여줄 것이라고 생각합니다. – user6461581

+0

어떤 버전의 commons net을 사용하고 있습니까? –

답변

0

Apache commons net에 버그가 기록되었으며 문제가 해결되지 않았습니다.

기본적으로 ..... '일부 클라이언트는 현재 ProtocolCommand Listener를 지원하지 않습니다.' 어떻게이 코드를 실행하는 :

다음과 같은 링크에서 자세한 내용을 찾을 수 있습니다 ....

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