Solved

Writng a Java Telnet Client

Posted on 2001-08-01
2
722 Views
Last Modified: 2008-02-01
Hi,
   I am now writing a Java Client Telnet program to telnet to other server. I have new a Socket on the server on Port 23 which is the default telnet port. However, when I run the program:

c:>java JavaTelnet xxx.yyy.com

server is : xxx.yyy.com
server socket connected! Socket[addr=xxx.yyy.com/192.168.1.1.,port=23, localport=1212]

then.. the program keep waiting and has no any reply from the server. Can anyone tell me what have I missed? Thanks!


import java.io.*;
import java.net.*;

public class JavaTelnet {
    public static void main(String[] args) throws IOException {

          //The args should be the server host name
        Socket telnetSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;
        String host = null;
       
        if (args!=null && args.length>0){
          if (args[0]!=null && !args[0].equals("")){
               host = args[0];
                  try {
                      telnetSocket = new Socket(host, 23);
                      out = new PrintWriter(telnetSocket.getOutputStream(), true);
                      in = new BufferedReader(new InputStreamReader(
                                                  telnetSocket.getInputStream()));
                  } catch (UnknownHostException e) {
                      System.err.println("Don't know about host: " + host + ".");
                      System.exit(1);
                  } catch (IOException e) {
                      System.err.println("Couldn't get I/O for "
                                         + "the connection to: "+ host +".");
                      System.exit(1);
                  }
                  System.out.println("server is : " + host);
                  System.out.println("server socket connected! " + telnetSocket.toString());
                  System.out.println(in.readLine());
                  System.out.println("from server: " + in.readLine());
                 
         
               BufferedReader stdIn = new BufferedReader(
                                             new InputStreamReader(System.in));
               String userInput;
         
               while ((userInput = stdIn.readLine()) != null) {
                   out.println(userInput);
                   System.out.println("telnet: " + in.readLine());
               }
         
               out.close();
               in.close();
               stdIn.close();
               telnetSocket.close();              
          }
        }
    }
}
0
Comment
Question by:john_law70
  • 2
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 30 total points
ID: 6344059
It's not that simple, read the telnet rfc:

http://www.faqs.org/rfcs/rfc854.html

Here's a telnet client with source:

http://www.mud.de/se/jta/


0
 
LVL 92

Expert Comment

by:objects
ID: 6391338
Thanks for the points and best of luck :)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now