远程通信
客户端
1
using System;2
using System.Runtime.Remoting.Channels;3
using System.Runtime.Remoting.Channels.Tcp;4

5
namespace Wrox.ProfessionalCsharp6


{7

/**////<summary>8
/// Summary description for Class1.9
///</summary>10

11
public class HelloClient12

{13
public static void Main()14

{15
ChannelServices.RegisterChannel(new TcpClientChanel());16
Hello obj = (Hello)Activator.GetObject(typeof(Hello),17
"tcp://localhost:8086/Hi");18
if (obj == null)19

{20
Console.WriteLine("could not locate server");21
return;22
}23
for (int i = 0; i < 5; i++)24

{25
Console.WriteLine(obj.Greeting("Christian"));26
}27
}28
}29
}服务器端
Server端
1
using System;2
using System.Runtime.Remoting;3
using System.Runtime.Remoting.Channels.Tcp;4

5
namespace Wrox.ProfessionalCSharp6


{7

/**////<summary>8
/// Summary description for Class1.9
///</summary>10

11
public class HelloServer12

{13
public static void Main(string[] args)14

{15
TpcServerChannel channel = new TcpServerChannel(8086);16
ChannelServices.RegisterChannel(channel);17
RemotingConfiguration.18
RegisterWellKnownServiceType(typeof(Hello), "Hi", WellKnownObjectMode.SingleCall);19
System.Console.WriteLine("hit to exit");20
System.Console.ReadLine();21
}22
}23
}posted on 2008-10-21 13:35 ForestSheep 阅读(211) 评论(0) 收藏 举报
浙公网安备 33010602011771号