zoukankan      html  css  js  c++  java
  • Remoting 技术

    Remoting 是基于TCP连接的,要实现她要先创建一个类库,然后将类库的dll文件引用到服务端和客户端

    类库的主要代码:

    创建一个类库叫Compute ,在类库中创建一个接口ICompute

    ICompte的代码:

    public interface ICompute

    {

      int Mutil(int a, int b);

    }

    定义一个Mathes的类,必须继承一个支持远程访问的对象

    public class Mathes : MarshalByRefObject , ICompute

    {

      public Mathes()

      {

        Console.WriteLine("创建一个对象实例");

      }

      #region ICompute 成员

      public int Mutil(int a, int b)

      {

        return a * b;

      }

      #endregion

    }

    创建一个控制台程序

    服务器的主要代码:

    static void Main(string[] args)

    {

      Console.WriteLine("服务器");

      //注册一个通道

      ChannelServices.RegisterChannel(new TCPServerChannel(50000));

      //注册一个类型

      RemotingConfiguration.RegisterWellKnownServiceType(typeof(Compute.Mathes),"abc",WellKnownObjectMode.Singleton);

      Console.Read();

    }

    客户端主要代码:

    static void Main(string[] args)

    {

      Console.WriteLine("客户端");

      //注册一个通道,不需要指定端口号

      ChannelServices.RegisterChannel(new TcpChannel());

      //获取类型的实例

      Compute.Mathes ma = Activator.GetObject(typeof(Compute.Mathes),"tcp://127.0.0.1:50000/abc") as Compute.Mathes;

      int result = ma.Mutil(2,3);

      Console.WriteLine(result);

      Console.Read(); 

    }

  • 相关阅读:
    计算机网络第五版答案 谢希仁
    AJAX代码示例(不使用AJAX控件)
    软件工程期末资料
    各类编程语言视频教程(300G)
    AJAX无刷新分页练习
    C#使用IrisSkin2.dll美化WinForm程序界面
    asp.net判断浏览器版本代码
    C#中国身份证验证
    在IIS中使用SSL配置HTTPS网站(转)
    silverLight导出报表
  • 原文地址:https://www.cnblogs.com/jasonjiang/p/1764491.html
Copyright © 2011-2022 走看看