国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

.net remoting范例

2024-07-10 12:58:49
字體:
來源:轉載
供稿:網友
 

1:創建一個工程文件,是server端的。

using system;
using system.runtime.remoting;
using system.runtime.remoting.channels;
using system.runtime.remoting.channels.tcp;

namespace helloserver
{
 /// <summary>
 /// class1 的摘要說明。
 /// </summary>
 class hs
 {
  /// <summary>
  /// 應用程序的主入口點。
  /// </summary>
  [stathread]
  static void main(string[] args)
  {
   //
   // todo: 在此處添加代碼以啟動應用程序
   //
   try
   {
    tcpserverchannel channel =new tcpserverchannel(8086);
    channelservices.registerchannel(channel);
    type t=typeof(remotehello.hello);   
    remotingconfiguration.registerwellknownservicetype(t,"hi",wellknownobjectmode.singlecall);
    console.writeline("hit to exit");
    console.readline();
   }
   catch (exception ex)
   {
    console.writeline(ex.message);
    console.writeline(ex.source);
    console.readline();
   }
  }
 }
}

2:創建一個工程文件是client端的:

using system;
using system.runtime.remoting.channels;
using system.runtime.remoting.channels.tcp;

namespace helloclient
{
 /// <summary>
 /// class1 的摘要說明。
 /// </summary>
 class hc
 {
  /// <summary>
  /// 應用程序的主入口點。
  /// </summary>
  [stathread]
  static void main(string[] args)
  {
   //
   // todo: 在此處添加代碼以啟動應用程序
   //
   try
   {
    tcpclientchannel tc=new tcpclientchannel();
    channelservices.registerchannel(tc);
    remotehello.hello obj = (remotehello.hello)activator.getobject(typeof(remotehello.hello),"tcp://10.10.10.111:8086/hi");
    if(obj==null)
    {
     console.writeline("failed!");
     return;
    }
    for(int i=0;i<2;i++)
    {
     console.writeline(obj.greeting("haha"));
     console.readline();
    }
   }
   catch (exception ex)
   {
    console.writeline(ex.message);
    console.writeline(ex.source);
    console.readline();
   }   
  }
 }
}

3:在編譯完以后,先運行server.exe文件,然后再運行client.exe文件,,,這樣在ms-dos下面,就可以看到,client掉用server。。。

呵呵。。。完畢。。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昭觉县| 泊头市| 沈丘县| 龙川县| 玉门市| 惠安县| 乌拉特中旗| 鹤壁市| 平陆县| 翁牛特旗| 嘉鱼县| 资兴市| 定陶县| 潮州市| 冷水江市| 铜鼓县| 唐山市| 谢通门县| 宝鸡市| 昂仁县| 定襄县| 伊春市| 三都| 石阡县| 益阳市| 宣威市| 慈溪市| 云阳县| 曲靖市| 会同县| 通许县| 原平市| 秦安县| 建湖县| 宁陵县| 宜城市| 舞阳县| 确山县| 钦州市| 恩平市| 信宜市|