Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Writng a Java Telnet Client

Posted on 2001-08-01
2
Medium Priority
?
799 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 90 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

670 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