Exemplo n.º 1
0
    protected static bool RegisterChannnel(int IP)
    {
        // リモート用として、クライアントチャンネルを登録。登録系は同じプロセス内で複数回やるとエラーが出るので、
        try
        {
            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(ch[IP], false);

            // リモート呼び出しのため、(サーバーにある)オブジェクト取得。
            // Register as client for remote object.
            System.Runtime.Remoting.WellKnownClientTypeEntry remoteType = new System.Runtime.Remoting.WellKnownClientTypeEntry(typeof(HmNodeRemoteObject), "ipc://localhost:" + IP + "/" + HmNodeRemoteObject.Name + IP + ".rem");

            // クライアントタイプとして登録
            System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownClientType(remoteType);

            // 通知先(Message Sink)のインスタンス生成
            string objectUri;
            System.Runtime.Remoting.Messaging.IMessageSink messageSink = (ch[IP]).CreateMessageSink("ipc://localhost:" + IP + "/" + HmNodeRemoteObject.Name + IP + ".rem", null, out objectUri);
            Console.WriteLine("通知先のURIは {0}.", objectUri);
            if (messageSink != null)
            {
                Console.WriteLine("通知先のクラス型は {0}.", messageSink.GetType().ToString());
            }
        }
        catch (Exception e)
        {
            System.Diagnostics.Debug.WriteLine(e.GetType().ToString());
            System.Diagnostics.Debug.WriteLine(e.Message);

            return(false);
        }

        return(true);
    }
    public static void Main(string[] args)
    {
        // Create the channel.
        HttpClientChannel clientChannel = new HttpClientChannel();

        // Register the channel.
        ChannelServices.RegisterChannel(clientChannel);

        // Register as client for remote object.
        WellKnownClientTypeEntry remoteType =
            new WellKnownClientTypeEntry(typeof(RemoteObject),
                                         "http://localhost:9090/RemoteObject.rem");

        RemotingConfiguration.RegisterWellKnownClientType(remoteType);

        // Create a message sink.
        string objectUri;

        System.Runtime.Remoting.Messaging.IMessageSink messageSink =
            clientChannel.CreateMessageSink(
                "http://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());
        }

        // Display the channel's properties using Keys and Item.
        foreach (string key in clientChannel.Keys)
        {
            Console.WriteLine(
                "clientChannel[{0}] = <{1}>",
                key, clientChannel[key]);
        }

        // Parse the channel's URI.
        string objectUrl  = "http://localhost:9090/RemoteObject.rem";
        string channelUri = clientChannel.Parse(objectUrl, out objectUri);

        Console.WriteLine("The object URL is {0}.", objectUrl);
        Console.WriteLine("The object URI is {0}.", objectUri);
        Console.WriteLine("The channel URI is {0}.", channelUri);

        // 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.");
        Console.WriteLine("The remote object has been called {0} times.",
                          service.GetCount());
    }
Exemplo n.º 3
0
    public static void Main(string[] args)
    {
        //<snippet31>
        // Create the channel.
        TcpClientChannel clientChannel = new TcpClientChannel("Client", null);

        //</snippet31>

        // Register the channel.
        ChannelServices.RegisterChannel(clientChannel);

        // Register as client for remote object.
        WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(
            typeof(RemoteObject), "tcp://localhost:9090/RemoteObject.rem");

        RemotingConfiguration.RegisterWellKnownClientType(remoteType);

        //<snippet32>
        // Create a message sink.
        string objectUri;

        System.Runtime.Remoting.Messaging.IMessageSink messageSink =
            clientChannel.CreateMessageSink(
                "tcp://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());
        }
        //</snippet32>

        //<snippet33>
        // Parse the channel's URI.
        string objectUrl  = "tcp://localhost:9090/RemoteObject.rem";
        string channelUri = clientChannel.Parse(objectUrl, out objectUri);

        Console.WriteLine("The object URL is {0}.", objectUrl);
        Console.WriteLine("The object URI is {0}.", objectUri);
        Console.WriteLine("The channel URI is {0}.", channelUri);
        //</snippet33>

        // 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.");
        Console.WriteLine("The remote object has been called {0} times.",
                          service.GetCount());
    }
Exemplo n.º 4
0
        public void Run()
        {
            AllocConsole();


            // Create the channel.
            TcpChannel clientChannel = new TcpChannel();


            // Register the channel.
            ChannelServices.RegisterChannel(clientChannel, true);

            // Register as client for remote object.
            WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(
                typeof(ConsoleLoggerProxy), "tcp://localhost:9090/LoggerProxy.rem");

            RemotingConfiguration.RegisterWellKnownClientType(remoteType);

            // Create a message sink.
            string objectUri;

            System.Runtime.Remoting.Messaging.IMessageSink messageSink =
                clientChannel.CreateMessageSink(
                    "tcp://localhost:" + TcpController.Port + "/LoggerProxy.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.
            ConsoleLoggerProxy service = new ConsoleLoggerProxy();

            // Invoke a method on the remote object.
            Console.WriteLine("The client is invoking the remote object.");
            Console.WriteLine("The remote object has been called {0} times.",
                              service.GetCount());

            while (true)
            {
                while (service.Count > 0)
                {
                    Console.WriteLine(service.Dequeue());
                }
            }
        }
Exemplo n.º 5
0
    [SecurityPermission(SecurityAction.Demand)] //wtf even is this
    public static void Main(string[] args)
    {
        // Krijo channel
        IpcChannel channel = new IpcChannel();

        // Regjistro channel, percakto sigurine
        System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false);

        // Regjistro se qka do dergohet, dhe ku
        System.Runtime.Remoting.WellKnownClientTypeEntry remoteType =
            new System.Runtime.Remoting.WellKnownClientTypeEntry(
                typeof(RemoteObject),
                "ipc://localhost:9090/RemoteObject.rem");
        System.Runtime.Remoting.RemotingConfiguration.
        RegisterWellKnownClientType(remoteType);
        // Krijo nje pool te mesazheve
        string objectUri;

        System.Runtime.Remoting.Messaging.IMessageSink messageSink =
            channel.CreateMessageSink(
                "ipc://localhost:9090/RemoteObject.rem", null,
                out objectUri);
        Console.WriteLine("URI e pool te mesazheve eshte {0}.",
                          objectUri);
        if (messageSink != null)
        {
            Console.WriteLine("Lloji i pool te mesazheve eshte {0}.",
                              messageSink.GetType().ToString());
        }

        // Krijo instanc te RemoteObject
        RemoteObject service = new RemoteObject();

        // Thirr metoden e RemoteObject
again:
        Console.WriteLine("Klienti po therret remote object.");
        Console.WriteLine("Remote objecti eshte thirrur " + service.GetCount() + " here.");
        // Mundesi e thjeshte per te perseritur thirrjen
        Console.Write("Deshironi t'e perseritni? (1=po, 0=jo): ");
        int repeat = 1;

        try{ repeat = Int32.Parse(Console.ReadLine()); }
        catch { repeat = 1; }
        if (repeat == 1)
        {
            goto again;
        }
    }
Exemplo n.º 6
0
    public static void Main(string[] args)
    {
        //<snippet21>
        // Create the channel.
        IpcChannel channel = new IpcChannel();

        //</snippet21>

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

        // 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);

        //<snippet22>
        // 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());
        }
        //</snippet22>

        // 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.");
        Console.WriteLine("The remote object has been called {0} times.",
                          service.GetCount());
    }