simple-example.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // compile with:
  11. // csc -r:../../lib/System.Runtime.Remoting.dll simple-example.cs
  12. class Test : MarshalByRefObject {
  13. public int test_function (int a, bool b)
  14. {
  15. Console.WriteLine ("test function called: " + b);
  16. return a + 1;
  17. }
  18. static int Main () {
  19. Test t1 = new Test ();
  20. ObjRef myref = RemotingServices.Marshal (t1, "/test");
  21. Console.WriteLine ("OBJREF: " + myref.URI);
  22. string url = "simple://localhost:8000/test";
  23. string uri;
  24. SimpleChannel chnl = new SimpleChannel (8000);
  25. ChannelServices.RegisterChannel (chnl);
  26. Console.WriteLine ("Channel name: " + chnl.ChannelName);
  27. Console.WriteLine ("Channel priority: " + chnl.ChannelPriority);
  28. Console.WriteLine ("URI: " + chnl.Parse (url, out uri));
  29. Console.WriteLine ("URI: " + uri);
  30. Test tp = (Test)RemotingServices.Connect (typeof (Test), url);
  31. int res = tp.test_function (4, true);
  32. Console.WriteLine ("RESULT: " + res);
  33. chnl.StopListening (null);
  34. return 0;
  35. }
  36. }