1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package examples;
17
18 import java.io.IOException;
19 import org.apache.commons.net.telnet.TelnetClient;
20
21 /***
22 * This is an example of a trivial use of the TelnetClient class.
23 * It connects to the weather server at the University of Michigan,
24 * um-weather.sprl.umich.edu port 3000, and allows the user to interact
25 * with the server via standard input. You could use this example to
26 * connect to any telnet server, but it is obviously not general purpose
27 * because it reads from standard input a line at a time, making it
28 * inconvenient for use with a remote interactive shell. The TelnetClient
29 * class used by itself is mostly intended for automating access to telnet
30 * resources rather than interactive use.
31 * <p>
32 ***/
33
34
35 public final class weatherTelnet
36 {
37
38 public final static void main(String[] args)
39 {
40 TelnetClient telnet;
41
42 telnet = new TelnetClient();
43
44 try
45 {
46 telnet.connect("rainmaker.wunderground.com", 3000);
47 }
48 catch (IOException e)
49 {
50 e.printStackTrace();
51 System.exit(1);
52 }
53
54 IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(),
55 System.in, System.out);
56
57 try
58 {
59 telnet.disconnect();
60 }
61 catch (IOException e)
62 {
63 e.printStackTrace();
64 System.exit(1);
65 }
66
67 System.exit(0);
68 }
69
70 }
71
72