日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Remoting 技术

發布時間:2025/7/25 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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();?

}

?

轉載于:https://www.cnblogs.com/jasonjiang/archive/2010/06/24/1764491.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的Remoting 技术的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。