Solved

Writng a Java Telnet Client

Posted on 2001-08-01
2
743 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

831 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