📄 cityweatherreportclient.java
字号:
import java.rmi.*;
public class cityWeatherReportClient
{
/* 城市天气服务器的客户端 */
public static void main(String[] args)
{
Remote remo = null;
int i = -1;
cityWeatherReportServer_Factory cwrs_factory = null; //建立远程服务器的Factory对象
cityWeatherReportInterface cwri = null; //建立接口对象
String RemoteSerHost = null;
String cityTemperature = null;
String cityWeatherInfo = null;
String[] cityName = {"巴 黎","北 京","大 阪","高 雄","汉 堡","汉 城","华 盛 顿","伦 敦","罗 马","马 德 里","曼 谷","温 哥 华","乌鲁木齐","悉 尼","新 加 坡","雅 典","乌鲁木齐","广 州","上 海"};
try
{
RemoteSerHost = "//127.0.0.1/cityWeatherReport_Factory";
remo = Naming.lookup(RemoteSerHost);
if(remo instanceof cityWeatherReportServer_Factory)
{
cwrs_factory = (cityWeatherReportServer_Factory) remo;
}
System.out.println("\n客户机已启动...\n");
for(i = 0;i < cityName.length;i++)
{
try
{
/* 开始为每一个查询请求建立一个服务器进程 */
cwri = new cityWeatherReportServer_Factory().getcityWeatherReport(cityName[i]);
/* 调用服务器端的getCityTemperature()和getWeatherForecast()方法 */
cityTemperature = cwri.getCityTemperature(); //提交温度查询
cityWeatherInfo = cwri.getWeatherForecast(); //提交天气查询
System.out.println("\n" + cityName[i] + "的天气预报:\n" + " 温 度:" + cityTemperature + "\n 天气情况:" + cityWeatherInfo);
}
catch(RemoteException e)
{
System.out.println("在提交天气情况查询请求时,系统抛出例外:" + e.toString());
}
}
System.out.println("\n数据传输完毕!");
}
catch(Exception e)
{
System.out.println("!客户机在运行中抛出例外:" + e.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -