Program: Telnet Client

This program is a simple Telnet client. Telnet, as you probably know, is the oldest surviving remote login program in use on the Internet. It began on the original ARPAnet and was later translated for the Internet. A Unix command-line client lives on, and there are several windowed clients in circulation. For security reasons, the use of Telnet as a means of logging in remotely over the Internet has largely been superseded by SSH (see http://www.openssh.com). However, a Telnet client remains a necessity for such purposes as connecting locally, as well as debugging textual socket servers and understanding their protocols. For example, it is common to connect from a Telnet client to an SMTP (email) server; you can often intuit quite a bit about the SMTP server even if you wouldn’t normally type an entire mail session interactively.

When you need to have data copied in both directions at more or less the same time -- from the keyboard to the remote program, and from the remote program to the screen -- there are two approaches. Some I/O libraries in C have a function called poll( ) or select( ) that allows you examine a number of files to see which ones are ready for reading or writing. Java does not support this model. The other model, which works on most platforms and is the norm in Java, is to use two threads,[35] one to handle the data transfer in each direction. That is our plan here; the class Pipe encapsulates one thread and the code for copying data in ...

Get Java Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.