zoukankan      html  css  js  c++  java
  • ipc的remoting

    远程对象:

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Object
    {
        
    public class MyObject : MarshalByRefObject
        {
            
    public int Add(int a, int b)
            {
                
    return a + b;
            }
        } 

    }

    1、配置文件方式

    服务端:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.Remoting;

    namespace Server
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                RemotingConfiguration.Configure(
    "Server.exe.config");
                Console.ReadLine();

            }
        }
    }

    服务端配置文件:
    <configuration>
        
    <system.runtime.remoting>
            
    <application name="RemoteServer">
                
    <service>
                    
    <wellknown type="Object.MyObject,Object" objectUri="Object.MyObject" mode="Singleton" />
                
    </service>
                
    <channels>
                    
    <channel ref="ipc" portName="testPipe" />
                
    </channels>
            
    </application>
        
    </system.runtime.remoting>
    </configuration>

    客户端:
    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Client
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                Object.MyObject app 
    = (Object.MyObject)Activator.GetObject(typeof(Object.MyObject), "ipc://testPipe/Object.MyObject");
                Console.WriteLine(app.Add(
    12));
                Console.ReadLine();

            }
        }
    }

    2、代码方式

    服务端:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.Remoting.Channels.Ipc; 
    using System.Runtime.Remoting.Channels;
    using System.Runtime.Remoting;

    namespace Server
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                IpcChannel ipcCh 
    = new IpcChannel("testPipe");
                ChannelServices.RegisterChannel(ipcCh);
                RemotingConfiguration.RegisterWellKnownServiceType
                   (
    typeof(Object.MyObject), "Object.MyObject", WellKnownObjectMode.Singleton);
                Console.ReadLine();

            }
        }
    }

    客户端和配置文件方式相同
  • 相关阅读:
    pamamiko的学习笔记
    pamamiko的安装
    python基本语法1.1--十进制与十六进制数之间的相互转换
    mnist深入--用卷积神经网络改善mnist
    minst数据集怎么跑
    七大常见排序算法总结(Java语言)
    ubuntu 16.03 Anaconda Tensorflow(CPU)安装
    IntelliJ Idea 2017 免费激活方法
    Ubuntu下安装deb格式的软件
    win10下配置java环境
  • 原文地址:https://www.cnblogs.com/lovecherry/p/582927.html
Copyright © 2011-2022 走看看