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