Advertisement
Guest User

Untitled

a guest
May 2nd, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. /**
  5.  * Telnet - connect to a given host and service
  6.  * This does not hold a candle to a real Telnet client, but
  7.  * shows some ideas on how to implement such a thing.
  8.  * @version $Id: Telnet.java,v 1.11 2004/02/16 02:44:43 ian Exp $
  9.  */
  10. public class telnet3 {
  11.     String host;
  12.     int portNum;
  13.     public static void main(String[] argv) {
  14.         ebauche_isn window = new ebauche_isn();
  15.         window.frmInterfaceRap.setVisible(true);
  16.         new telnet3().talkTo(argv);
  17.     }
  18.     private void talkTo(String av[]) {
  19.  
  20.         System.out.println(ebauche_isn.x);
  21.         if (av.length >= 1)
  22.             host = av[0];
  23.         else
  24.             host = "192.168.0.105";
  25.         if (av.length >= 2)
  26.             portNum = Integer.parseInt(av[1]);
  27.         else portNum = 80;
  28.         System.out.println("Host " + host + "; port " + portNum);
  29.         try {
  30.             Socket s = new Socket(host, portNum);
  31.  
  32.             // Connect the remote to our stdout
  33.             new Pipe(s.getInputStream(), System.out).start();
  34.  
  35.             // Connect our stdin to the remote
  36.             new Pipe(System.in, s.getOutputStream()).start();
  37.  
  38.         } catch(IOException e) {
  39.             System.out.println(e);
  40.             return;
  41.         }
  42.         System.out.println("Connected OK");
  43.     }
  44.  
  45.     /* This class handles one half of a full-duplex connection.
  46.      * Line-at-a-time mode.
  47.      */
  48.     class Pipe extends Thread {
  49.         BufferedReader is;
  50.         PrintStream os;
  51.  
  52.         /** Construct a Pipe to read from is and write to os */
  53.         Pipe(InputStream is, OutputStream os) {
  54.             this.is = new BufferedReader(new InputStreamReader(is));
  55.             this.os = new PrintStream(os);
  56.         }
  57.  
  58.         /** Do the reading and writing. */
  59.         public void run() {
  60.        
  61.             String line;
  62.             System.out.println("ICI");
  63.             char h = ebauche_isn.x;
  64.             System.out.println(h);
  65.             try {
  66.                 while ((line = is.readLine()) != null) {
  67.                     os.print(h);
  68.                     os.print("\r\n");
  69.                     os.flush();
  70.                 }
  71.             } catch(IOException e) {
  72.                 throw new RuntimeException(e.getMessage());
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement