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(); 

    }

  • 相关阅读:
    vb.net FTP上传下载,目录操作
    vb.net导出CSV文件
    服务器内存总量
    定义数组
    监控键盘健代码
    C# FTp 上传,下载
    使用EasyUI中Tree
    微信web开发自定义分享
    mysql将时间戳格式化
    查询表时给字段赋默认值 sql
  • 原文地址:https://www.cnblogs.com/jasonjiang/p/1764491.html
Copyright © 2011-2022 走看看