001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package examples;
019
020 import java.io.IOException;
021 import org.apache.commons.net.telnet.TelnetClient;
022
023 /***
024 * This is an example of a trivial use of the TelnetClient class.
025 * It connects to the weather server at the University of Michigan,
026 * um-weather.sprl.umich.edu port 3000, and allows the user to interact
027 * with the server via standard input. You could use this example to
028 * connect to any telnet server, but it is obviously not general purpose
029 * because it reads from standard input a line at a time, making it
030 * inconvenient for use with a remote interactive shell. The TelnetClient
031 * class used by itself is mostly intended for automating access to telnet
032 * resources rather than interactive use.
033 * <p>
034 ***/
035
036 // This class requires the IOUtil support class!
037 public final class weatherTelnet
038 {
039
040 public final static void main(String[] args)
041 {
042 TelnetClient telnet;
043
044 telnet = new TelnetClient();
045
046 try
047 {
048 telnet.connect("rainmaker.wunderground.com", 3000);
049 }
050 catch (IOException e)
051 {
052 e.printStackTrace();
053 System.exit(1);
054 }
055
056 IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(),
057 System.in, System.out);
058
059 try
060 {
061 telnet.disconnect();
062 }
063 catch (IOException e)
064 {
065 e.printStackTrace();
066 System.exit(1);
067 }
068
069 System.exit(0);
070 }
071
072 }
073
074