Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Trying to create a GUI front end for a TELNET application

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trying to create a GUI front end for a TELNET application

    Dear Members,

    I am trying to create a GUI which will accept an IP ( in a JText Field ) and will connect to a TELNET server.
    It will then issue a couple of telnet commands (like username, password and another command ) and then it will close.

    I am trying to make use of the Java Cookbook's Telnet Client program (Section 16.9) and accommodate it to run with a simple input field and button in a GUI.

    TELNET Program:
    import java.net.*;
    import java.io.*;
    /**
     * Telnet - very minimal (no options); connect to given host and service
     */
    public class Telnet {
        String host;
        int portNum;
        public static void main(String[] argv) {
            new Telnet().talkTo(argv);
        }
        private void talkTo(String av[]) {
            if (av.length >= 1)
                host = av[0];
            else
                host = "localhost";
            if (av.length >= 2)
                portNum = Integer.parseInt(av[1]);
            else portNum = 23;
            System.out.println("Host " + host + "; port " + portNum);
            try {
                Socket s = new Socket(host, portNum);
                // Connect the remote to our stdout
                new Pipe(s.getInputStream(), System.out).start();
                // Connect our stdin to the remote
                new Pipe(System.in, s.getOutputStream()).start();
            } catch(IOException e) {
                System.out.println(e);
                return;
            }
            System.out.println("Connected OK");
        }
    }
    /* This class handles one half of a full-duplex connection.
     * Line-at-a-time mode.
     */
    class Pipe extends Thread {
        BufferedReader is;
        PrintStream os;
        /** Construct a Pipe to read from "is" and write to "os" */
        Pipe(InputStream is, OutputStream os) {
            this.is = new BufferedReader(new InputStreamReader(is));
            this.os = new PrintStream(os);
        }
        /** Do the reading and writing. */
        public void run() {
            String line;
            try {
                while ((line = is.readLine()) != null) {
                    os.print(line);
                    os.print("\r\n");
                    os.flush();
                }
            } catch(IOException e) {
                throw new RuntimeException(e.getMessage());
            }
        }
    }

    My problem is that I do not know how to combine the TELNET program which is a console input with a button that will read a user given text.

    What I am trying to achieve:
       private void JB_updateActionPerformed(java.awt.event.ActionEvent evt) {                                          
            // TODO add your handling code here:
            String user_IP;
     
            //Get IP from Java Text Field
            user_IP = JTF_Input.getText();
     
            // Do nothing if text field is empty
            // Or Print out IP 
            if (!"".equals(user_IP)) {
                //Start Telnet client and pass IP
                //Pass Username password
                //Pass command
                //Receive Confirmation
                //Disconnect on successful confirmation
     
            }
        }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Trying to create a GUI front end for a TELNET application

    Quote Originally Posted by arkroan View Post
    My problem is that I do not know how to combine the TELNET program which is a console input with a button that will read a user given text.
    public class PrettyTelnet extends Telnet

    set up your dialog to drop user input on the outgoing stream to the server and the user's display to show what the server sends back.

Similar Threads

  1. comparison of data from front-end jsp page to database values
    By yashwanthguru in forum JDBC & Databases
    Replies: 0
    Last Post: March 1st, 2013, 12:37 PM
  2. Create Application
    By sahilradotra in forum Java Theory & Questions
    Replies: 3
    Last Post: September 15th, 2012, 09:39 PM
  3. alert box in front end to display errors in backend
    By nischalinn in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: July 24th, 2012, 11:16 PM
  4. Replies: 0
    Last Post: June 13th, 2012, 06:44 PM
  5. Replies: 3
    Last Post: February 1st, 2010, 12:24 AM