17,740
社区成员
发帖
与我相关
我的任务
分享
using System;
namespace Wrox.ProCSharp.Remoting
{
public class Hello: System.MarshalByRefObject
{
public Hello()
{
Console.WriteLine("构造函数启动了!");
}
~Hello()
{
Console.WriteLine("析构函数启动了!");
}
public string Greeting(string name)
{
Console.WriteLine("问候启动了!");
return "你好," + name;
}
}
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace Wrox.ProCSharp.Remoting
{
class Program
{
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello), "Hi", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("press return to exit");
System.Console.ReadLine();
}
}
}
using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace Wrox.ProCSharp.Remoting
{
class Program
{
static void Main(string[] args)
{
ChannelServices.RegisterChannel(new TcpClientChannel(), false);
Hello obj = (Hello)Activator.GetObject(typeof(Hello), "tcp://localhost:8086/Hi");
if (obj == null)
{
Console.WriteLine("could not locate server");
return;
}
for (int i = 0; i < 5; i++)
{
Console.WriteLine(obj.Greeting("你好!"));
}
}
}
}