远程通信
客户端
Client
1using System;
2using System.Runtime.Remoting.Channels;
3using System.Runtime.Remoting.Channels.Tcp;
4
5namespace Wrox.ProfessionalCsharp
6{
7 /**////<summary>
8 /// Summary description for Class1.
9 ///</summary>
10
11 public class HelloClient
12 {
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}
1using System;
2using System.Runtime.Remoting.Channels;
3using System.Runtime.Remoting.Channels.Tcp;
4
5namespace Wrox.ProfessionalCsharp
6{
7 /**////<summary>
8 /// Summary description for Class1.
9 ///</summary>
10
11 public class HelloClient
12 {
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端
1using System;
2using System.Runtime.Remoting;
3using System.Runtime.Remoting.Channels.Tcp;
4
5namespace Wrox.ProfessionalCSharp
6{
7 /**////<summary>
8 /// Summary description for Class1.
9 ///</summary>
10
11 public class HelloServer
12 {
13 public static void Main(string[] args)
14 {
15 TpcServerChannel channel = new TcpServerChannel(8086);
16 ChannelServices.RegisterChannel(channel);
17 RemotingConfiguration.
18RegisterWellKnownServiceType(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 阅读(207) 评论(0) 编辑 收藏 举报