Example #1
0
        public void MainFunc()
        {
            // Создаём каналы
            IpcChannel channel1 = new IpcChannel();
            IpcChannel channel2 = new IpcChannel();
            IpcChannel channel3 = new IpcChannel();

            // Регистрируем канал.
            System.Runtime.Remoting.Channels.ChannelServices.
            RegisterChannel(channel1, false);

            // Регистрируем клиентские удалённые обьекты.
            System.Runtime.Remoting.WellKnownClientTypeEntry remoteType1 =
                new System.Runtime.Remoting.WellKnownClientTypeEntry(
                    typeof(ClassLibrary1.Class1),
                    "ipc://localhost:9090/RemoteObject1.rem");

            System.Runtime.Remoting.WellKnownClientTypeEntry remoteType2 =
                new System.Runtime.Remoting.WellKnownClientTypeEntry(
                    typeof(ClassLibrary2.Class2),
                    "ipc://localhost:9090/RemoteObject2.rem");

            System.Runtime.Remoting.WellKnownClientTypeEntry remoteType3 =
                new System.Runtime.Remoting.WellKnownClientTypeEntry(
                    typeof(ClassLibrary3.Class3),
                    "ipc://localhost:9090/RemoteObject3.rem");

            System.Runtime.Remoting.RemotingConfiguration.
            RegisterWellKnownClientType(remoteType1);
            System.Runtime.Remoting.RemotingConfiguration.
            RegisterWellKnownClientType(remoteType2);
            System.Runtime.Remoting.RemotingConfiguration.
            RegisterWellKnownClientType(remoteType3);

            // Создаём приемники сообщений
            string objectUri;

            System.Runtime.Remoting.Messaging.IMessageSink messageSink1 =
                channel1.CreateMessageSink(
                    "ipc://localhost:9090/RemoteObject1.rem", null,
                    out objectUri);
            System.Runtime.Remoting.Messaging.IMessageSink messageSink2 =
                channel2.CreateMessageSink(
                    "ipc://localhost:9090/RemoteObject2.rem", null,
                    out objectUri);
            System.Runtime.Remoting.Messaging.IMessageSink messageSink3 =
                channel3.CreateMessageSink(
                    "ipc://localhost:9090/RemoteObject3.rem", null,
                    out objectUri);

            // Создание экземпляра удаленного объекта
            service1 = new ClassLibrary1.Class1();
            service2 = new ClassLibrary2.Class2();
            service3 = new ClassLibrary3.Class3();

            return;
        }
Example #2
0
        internal static void SendMessage(string[] args)
        {
            try
            {
                var channel = new IpcChannel();

                System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, true);

                //Register as client for remote object.
                var remoteType = new System.Runtime.Remoting.WellKnownClientTypeEntry(typeof(InterProcessRemoteObject), "ipc://localhost:9192/ScreenToGifRemoteObject.rem");
                System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownClientType(remoteType);

                var service = new InterProcessRemoteObject();
                service.SendArguments(args);
            }
            catch (Exception e)
            {
                LogWriter.Log(e, "It was not possible to send a message via the IPC server.");
            }
        }
Example #3
0
        public static void SendParameter(string parameter)
        {
            // Create the channel.
            IpcChannel channel = new IpcChannel();

            // Register the channel.
            System.Runtime.Remoting.Channels.ChannelServices.
                RegisterChannel(channel, false);

            // Register as client for remote object.
            System.Runtime.Remoting.WellKnownClientTypeEntry remoteType =
                new System.Runtime.Remoting.WellKnownClientTypeEntry(
                    typeof(RemoteObject),
                    "ipc://localhost:9090/RemoteObject.rem");
            System.Runtime.Remoting.RemotingConfiguration.
                RegisterWellKnownClientType(remoteType);

            // Create a message sink.
            //string objectUri;
            //System.Runtime.Remoting.Messaging.IMessageSink messageSink =
            //    channel.CreateMessageSink(
            //        "ipc://localhost:9090/RemoteObject.rem", null,
            //        out objectUri);
            //Console.WriteLine("The URI of the message sink is {0}.",
            //    objectUri);
            //if (messageSink != null)
            //{
            //    Console.WriteLine("The type of the message sink is {0}.",
            //        messageSink.GetType().ToString());
            //}

            // Create an instance of the remote object.
            RemoteObject service = new RemoteObject();

            // Invoke a method on the remote object.
            Console.WriteLine("The client is invoking the remote object.");
            service.Execute(parameter);
        }
        public override void Open()
        {
            IpcChannel channel = new IpcChannel();

            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false);

            string host = string.Format("ipc://localhost:{0}", Port);

            System.Runtime.Remoting.WellKnownClientTypeEntry remoteType =
                new System.Runtime.Remoting.WellKnownClientTypeEntry(
                    typeof(FARemoteObject), host + "/RemoteObject.rem");

            System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownClientType(remoteType);

            string objectUri;
            System.Runtime.Remoting.Messaging.IMessageSink messageSink = channel.CreateMessageSink(
                    host + "/RemoteObject.rem", null,
                    out objectUri);

            if (messageSink == null)
            {
                throw new Exception(string.Format("{0} Open fail. fail create message sink", Name));
            }

            _service = new FARemoteObject();

            try
            {
                _service.ConnectTest(); // 최초 접속을 시도한다.
            }
            catch
            {
                // 접속에 실패해도 넘어간다. 이후 SetData(), GetData() 가 호출될 때 접속이 되는지 확인한다.
            }
        }