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

            }
        }
    }

    客户端和配置文件方式相同
  • 相关阅读:
    python scapy的用法之ARP主机扫描和ARP欺骗
    Python字典取键、值对
    python字典添加元素和删除元素
    Python删除列表元素
    获取本机的IP地址和mac地址
    Python查找电话号码归属地、邮编、运营商信息等
    Python的字符串格式化,%与format
    Python基础笔记一之字符转化、复数、位运算、除法运算、floor和ceil取整,round函数四舍五入
    FAILED: SemanticException Unable to determine if hdfs://tmaster:8020/user/root/words.db/test_t2 is encrypted
    Pyspark读取csv文件
  • 原文地址:https://www.cnblogs.com/lovecherry/p/582927.html
Copyright © 2011-2022 走看看