Program.Remoting.cs 1.4 KB

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