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

            }
        }
    }

    客户端和配置文件方式相同
  • 相关阅读:
    asr相关技术总结
    SLURM 使用基础教程
    FSMN 及其变种 cFSMN DFSMN pyramidal-FSMN
    均方根误差(RMSE),平均绝对误差 (MAE),标准差 (Standard Deviation)
    linux文本编码格式转化 字幕处理
    PyTorch-Kaldi 语音识别工具包
    SRILM Ngram 折扣平滑算法
    awk 调用 shell 命令,并传递参数
    用 scikit-learn 和 pandas 学习线性回归
    逻辑回归 及 实例
  • 原文地址:https://www.cnblogs.com/lovecherry/p/582927.html
Copyright © 2011-2022 走看看