Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- /**
- * Telnet - connect to a given host and service
- * This does not hold a candle to a real Telnet client, but
- * shows some ideas on how to implement such a thing.
- * @version $Id: Telnet.java,v 1.11 2004/02/16 02:44:43 ian Exp $
- */
- public class telnet3 {
- String host;
- int portNum;
- public static void main(String[] argv) {
- ebauche_isn window = new ebauche_isn();
- window.frmInterfaceRap.setVisible(true);
- new telnet3().talkTo(argv);
- }
- private void talkTo(String av[]) {
- System.out.println(ebauche_isn.x);
- if (av.length >= 1)
- host = av[0];
- else
- host = "192.168.0.105";
- if (av.length >= 2)
- portNum = Integer.parseInt(av[1]);
- else portNum = 80;
- 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;
- System.out.println("ICI");
- char h = ebauche_isn.x;
- System.out.println(h);
- try {
- while ((line = is.readLine()) != null) {
- os.print(h);
- os.print("\r\n");
- os.flush();
- }
- } catch(IOException e) {
- throw new RuntimeException(e.getMessage());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement