Program.Remoting.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections;
  3. using System.Drawing;
  4. using System.Reactive.Linq;
  5. using System.Runtime.Remoting.Channels;
  6. using System.Runtime.Remoting.Channels.Tcp;
  7. using System.Runtime.Serialization.Formatters;
  8. using System.Windows.Forms;
  9. using RxMouseService;
  10. namespace RxMouseClient
  11. {
  12. partial class Program
  13. {
  14. const string SERVICENAME = "MouseService";
  15. static IObservable<Point> Remoting(string srv, int port)
  16. {
  17. ConfigureRemoting();
  18. var ms = (IMouseService)Activator.GetObject(typeof(IMouseService), string.Format("tcp://{0}:{1}/{2}", srv, port, SERVICENAME));
  19. return ms.GetPoints();
  20. }
  21. private static void ConfigureRemoting()
  22. {
  23. var server = new BinaryServerFormatterSinkProvider();
  24. server.TypeFilterLevel = TypeFilterLevel.Full;
  25. var client = new BinaryClientFormatterSinkProvider();
  26. IDictionary props = new Hashtable();
  27. props["port"] = 0;
  28. props["name"] = SERVICENAME;
  29. props["typeFilterLevel"] = TypeFilterLevel.Full;
  30. ChannelServices.RegisterChannel(new TcpChannel(props, client, null), false);
  31. }
  32. }
  33. }