⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 helloserviceproxy.java

📁 《java网络编程精解》的源代码
💻 JAVA
字号:
package proxy1;
import java.util.Date;
public class HelloServiceProxy implements HelloService{
  private String host;
  private int port;
  
  public HelloServiceProxy(String host,int port){
     this.host=host;
     this.port=port;
  }
  public String echo(String msg)throws RemoteException{
    Connector connector=null;
    try{
      connector=new Connector(host,port);
      Call call=new Call("proxy1.HelloService","echo",new Class[]{String.class},new Object[]{msg}); 
      connector.send(call);
      call=(Call)connector.receive();
      Object result=call.getResult();
      if(result instanceof Throwable)
        throw new RemoteException((Throwable)result);
      else
        return (String)result;
    }catch(Exception e){
       throw new RemoteException(e);
    }finally{if(connector!=null)connector.close();}
  }

  public Date getTime()throws RemoteException{
    Connector connector=null;
    try{
      connector=new Connector(host,port);
      Call call=new Call("proxy1.HelloService","getTime",new Class[]{},new Object[]{}); 
      connector.send(call);
      call=(Call)connector.receive();
      Object result=call.getResult();
      if(result instanceof Throwable)
        throw new RemoteException((Throwable)result);
      else
        return (Date)result;
     }catch(Exception e){
       throw new RemoteException(e);
     }finally{if(connector!=null)connector.close();}
  }
} 


/****************************************************
 * 作者:孙卫琴                                     *
 * 来源:<<Java网络编程精解>>                       *
 * 技术支持网址:www.javathinker.org                *
 ***************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -