FileDocCategorySizeDatePackage
Telnet.javaAPI DocExample1621Sat Apr 28 20:36:02 BST 2001None

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.8 2001/04/28 23:36:03 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");