Debian Codegraph @

external/rx/Rx/NET/Samples/RxRemoteMouseMoves/RxMouseServer/Program.Remoting.cs

raw
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
10 namespace RxMouseServer
11 {
12 partial class Program
13 {
14 const string SERVICENAME = "MouseService";
15
16 static IObserver<Point> Remoting(int port)
17 {
18 ConfigureRemoting(port);
19
20 RemotingConfiguration.RegisterWellKnownServiceType(typeof(MouseService), SERVICENAME, WellKnownObjectMode.Singleton);
21
22 var ms = (IMouseService)Activator.GetObject(typeof(IMouseService), string.Format("tcp://{0}:{1}/{2}", "localhost", port, SERVICENAME));
23
24 return (IObserver<Point>)ms;
25 }
26
27 private static void ConfigureRemoting(int port)
28 {
29 var serverProvider = new BinaryServerFormatterSinkProvider();
30 serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
31
32 var clientProvider = new BinaryClientFormatterSinkProvider();
33
34 IDictionary props = new Hashtable();
35 props["port"] = port;
36 props["name"] = SERVICENAME;
37 props["typeFilterLevel"] = TypeFilterLevel.Full;
38
39 ChannelServices.RegisterChannel(new TcpChannel(props, clientProvider, serverProvider), false);
40 }
41 }
42 }