0
안녕하세요, 저는 자바에서 간단한 텔넷 소켓 클라이언트를 작성했으며 Windows 7 Pro 내의 localhost에서 텔넷 서비스에 연결하려고합니다. 코드가 잘 실행되고 있지만 출력 스트림을 출력하지 않고 코드 대신 다음 코드를 입력하면 오류가 발생합니다. 포트 1024에서 localhost 호스트에 연결하려고 시도합니다. 연결 대상 I/O를 가져올 수 없습니다. localhostjava telnet socket client
내가 뭔가 빠졌습니까 ??? 아래의 코드는 미리 감사드립니다.
import java.io.*;
import java.net.*;
import java.util.*;
public class telnetClients {
public static void main(String[] args) throws IOException {
String telnetServer = new String ("localhost");
int port = 1024;
if (args.length > 0)
telnetServer = args[0];
System.out.println ("Attemping to connect to host " +
telnetServer + " on port "
+ port);
Socket ClientSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
ClientSocket = new Socket(telnetServer, port);
ClientSocket.setSoTimeout(20000);
// PrintStream com = new PrintStream(ClientSocket.getOutputStream());
// System.out.println(com);
// BufferedReader inCom = new BufferedReader(new InputStreamReader (ClientSocket.getInputStream()));
out = new PrintWriter(ClientSocket.getOutputStream(), true);
System.out.println(out);
in = new BufferedReader(new InputStreamReader(
ClientSocket.getInputStream()));
String command = in.readLine();
if(in != null);
System.out.println(in);
} catch (UnknownHostException e) {
System.err.println("Don't know about host: " + telnetServer);
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to: " + telnetServer);
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;
System.out.println ("Type Message (\"bye\" to quit)");
while ((userInput = stdIn.readLine()) != null)
{
out.println(userInput);
// end loop
if (userInput.equals("bye"))
break;
System.out.println("echo: " + in.readLine());
}
out.close();
in.close();
stdIn.close();
ClientSocket.close();
}
}
보다는 예외가 무엇인지 무시하여이 작업을 수행 할 수 있기 때문에
그 후에는 포트를 구성해야합니다, 당신이 그것을 인쇄해야합니다 ('e.printStackTrace()'). 무엇이 잘못되었는지 알려줄 것입니다. –
해당 서비스가 사용 하시겠습니까? –
"연결에 대한 I/O를 가져올 수 없습니다."는 예외가 아닙니다. 예외를 잡았을 때 스스로 인쇄 한 것입니다. 그것은 쓸모가 없다. 당신이 인쇄해야 할 것은 * 예외 * 그 자체입니다. 그렇다면 무엇이 잘못되었는지 알 수 있습니다. – EJP