Java Reference
In-Depth Information
new
new Pipe ( System . in , s . getOutputStream ()). start ();
} catch
catch ( IOException e ) {
System . out . println ( e );
return
return ;
}
System . out . println ( "Connected OK" );
}
/* This class handles one half of a full-duplex connection.
* Line-at-a-time mode.
*/
class
class Pipe
extends Thread {
BufferedReader is ;
PrintStream os ;
Pipe extends
/** Construct a Pipe to read from is and write to os */
Pipe ( InputStream is , OutputStream os ) {
this
this . is = new
new BufferedReader ( new
new InputStreamReader ( is ));
this
this . os = new
new PrintStream ( os );
}
/** Do the reading and writing. */
public
public void
void run () {
String line ;
try
try {
while
while (( line = is . readLine ()) != null
null ) {
os . print ( line );
os . print ( "\r\n" );
os . flush ();
}
} catch
catch ( IOException e ) {
throw
throw new
new RuntimeException ( e . getMessage ());
}
}
}
}
Of course this is far from a complete “real” Telnet client, but you should be using SSH in-
stead of Telnet for real connectivity over the Internet; see http://openssh.com .
Search WWH ::




Custom Search