FileDocCategorySizeDatePackage
Telnet.javaAPI DocExample1634Sun Feb 15 20:44:44 GMT 2004None

Telnet

public class Telnet extends Object
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 $

Fields Summary
String
host
int
portNum
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

		new Telnet().talkTo(argv);
	
private voidtalkTo(java.lang.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");