📄 sincalculateclient.java
字号:
import java.rmi.*;
import java.net.*;
public class sinCalculateClient
{
/* 这是计算引擎的Client端的程序 */
/* 其作用是提交参数和显示计算服务器回复的计算结果 */
public static void main(String[] args)
{
sinCalculateClient sc = new sinCalculateClient();
String RemoteSerHost = null; //定义远程服务器连接串
int x[] = new int[13]; //存放函数自变量值
double y[] = new double[13]; //存放函数应变量值
int j = -1;
x = sc.ConvertStrToInt(args); //转换数值类型(String -> int)
RemoteSerHost = "//127.0.0.1/BlueICE";
try
{
/* 建立远程接口(Remote Interface)对象 */
System.out.print("开始建立Remote Server连接...");
sinCalculateInterface sci = (sinCalculateInterface)Naming.lookup(RemoteSerHost);
System.out.print("...连接成功!\n\n开始进行Remote Calculate ...\n\n");
for(j = 0;j < x.length;j++)
{
try
{
/* 调用服务器端的CalculateSin()方法进行计算,然后接收服务器反馈的结 */
y[j] = sci.CalculateSin(x[j]);
System.out.println("x = " + x[j] + " --> Server , y = " + y[j] + " --> Client");
}
catch(Exception e)
{
y[j] = -1;
System.out.println("x = " + x[j] + " --> Server , y = error! --> Client");
}
}
System.out.println("\n完成计算");
}
catch(Exception e)
{
System.out.println("Client端程序抛出例外:" + e.toString());
}
}
private int[] ConvertStrToInt(String[] Str)
{
/* 这是一个将字符串变量值转换成整型变量值的方法(函数) */
int i = -1;
String v = null;
int c = -1;
int Result[] = new int[Str.length];
for(i = 0;i < Str.length;i++)
{
/* 开始转换 */
try
{
c = Integer.parseInt(Str[i]);
Result[i] = c;
}
catch(Exception e)
{
Result[i] = 0;
}
}
return Result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -