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 018package examples.telnet; 019 020import java.io.IOException; 021import org.apache.commons.net.telnet.TelnetClient; 022 023import examples.util.IOUtil; 024 025/*** 026 * This is an example of a trivial use of the TelnetClient class. 027 * It connects to the weather server at the University of Michigan, 028 * um-weather.sprl.umich.edu port 3000, and allows the user to interact 029 * with the server via standard input. You could use this example to 030 * connect to any telnet server, but it is obviously not general purpose 031 * because it reads from standard input a line at a time, making it 032 * inconvenient for use with a remote interactive shell. The TelnetClient 033 * class used by itself is mostly intended for automating access to telnet 034 * resources rather than interactive use. 035 ***/ 036 037// This class requires the IOUtil support class! 038public final class WeatherTelnet 039{ 040 041 public static final void main(String[] args) 042 { 043 TelnetClient telnet; 044 045 telnet = new TelnetClient(); 046 047 try 048 { 049 telnet.connect("rainmaker.wunderground.com", 3000); 050 } 051 catch (IOException e) 052 { 053 e.printStackTrace(); 054 System.exit(1); 055 } 056 057 IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(), 058 System.in, System.out); 059 060 try 061 { 062 telnet.disconnect(); 063 } 064 catch (IOException e) 065 { 066 e.printStackTrace(); 067 System.exit(1); 068 } 069 070 System.exit(0); 071 } 072 073} 074 075