01: /*
02: * Copyright 2001-2005 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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: // This class requires the IOUtil support class!
35: public final class weatherTelnet {
36:
37: public final static void main(String[] args) {
38: TelnetClient telnet;
39:
40: telnet = new TelnetClient();
41:
42: try {
43: telnet.connect("rainmaker.wunderground.com", 3000);
44: } catch (IOException e) {
45: e.printStackTrace();
46: System.exit(1);
47: }
48:
49: IOUtil.readWrite(telnet.getInputStream(), telnet
50: .getOutputStream(), System.in, System.out);
51:
52: try {
53: telnet.disconnect();
54: } catch (IOException e) {
55: e.printStackTrace();
56: System.exit(1);
57: }
58:
59: System.exit(0);
60: }
61:
62: }
|