2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Runtime.Remoting / Test / simple-example.cs
1 using System;
2 using System.Threading;
3 using System.Runtime.InteropServices;
4 using System.Runtime.Remoting;
5 using System.Runtime.Remoting.Messaging;
6 using System.Runtime.Remoting.Proxies;
7 using System.Runtime.Remoting.Channels;
8 using System.Runtime.Remoting.Channels.Simple;
9 using System.IO;
10
11
12 // compile with:
13 // csc -r:../../lib/System.Runtime.Remoting.dll simple-example.cs
14
15 class Test : MarshalByRefObject {
16
17         public int test_function (int a, bool b)
18         {
19                 Console.WriteLine ("test function called: " + b);
20                 return a + 1;
21         }
22         
23         static int Main () {
24
25                 Test t1 = new Test ();
26                 ObjRef myref = RemotingServices.Marshal (t1, "/test");
27                 Console.WriteLine ("OBJREF: " + myref.URI);
28                 
29                 string url = "simple://localhost:8000/test";
30                 string uri;
31                 
32                 SimpleChannel chnl = new SimpleChannel (8000);
33                 ChannelServices.RegisterChannel (chnl);
34
35                 Console.WriteLine ("Channel name: " + chnl.ChannelName);
36                 Console.WriteLine ("Channel priority: " + chnl.ChannelPriority);
37                 Console.WriteLine ("URI: " + chnl.Parse (url, out uri));
38                 Console.WriteLine ("URI: " + uri);
39                 
40
41                 Test tp = (Test)RemotingServices.Connect (typeof (Test), url);
42
43                 int res = tp.test_function (4, true);
44
45                 Console.WriteLine ("RESULT: " + res);
46                 
47                 chnl.StopListening (null);
48                 
49                 return 0;
50         }
51 }