• 您的位置我爱Aspx >> VC.Net >> 程序员手记:简析Java RMI 与 .NET Remoting(原创)
  • 程序员手记:简析Java RMI 与 .NET Remoting(原创)

  • 作者:aspxer  来源:internet  日期:2007-5-21 23:49:03  关键字:.net
  • using System.Runtime.Remoting.Channels.Tcp;

    using RemoteSample;

    namespace RemoteSampleClient

    {

    public class RemoteClient

    {

    public static void Main(string[] args)

    {

    ChannelServices.RegisterChannel(new TcpClientChannel());

    RemoteObject remoteobj = (RemoteObject)Activator.GetObject( typeof(RemoteObject),

    "tcp://localhost:8808/RemoteObject");

    Console.WriteLine("1 + 2 = " + remoteobj.sum(1,2).ToString());

    Console.ReadLine();//在能够看到结果前不让窗口关闭

    }

    }

    }

    保存文件,命名为RemoteClient.cs

    用命令行csc /r:System.Runtime.Remoting.dll /r:RemoteObject.dll RemoteClient.cs 编译这一程序生成的RemoteClient.EXE文件。

    第四步:测试

    在windows中运行Server.exe,然后打开另一个窗体运行Client.exe。

    如果一切正常的话,客户端输出: 1 + 2 = 3。

    由此可见,NET Remoting不需要创建存根程序和骨架文件,使用起来比Java的RMI简单,而且为处理局域网甚至互联网范围内的资源提供了一个绝佳的方法,使用范围比Java的RMI更广泛。

    我对这篇文章有话说?
  • 广告位招租,广告代号:content_468_15
  • 上一篇:WIN32用户界面设计基础之Cursor篇
    下一篇:智力游戏九连环的算法