zoukankan      html  css  js  c++  java
  • c# Remoting小例子

    ///近最项目用到了Remoting ,自己学习了一下,在这里记一下。
    
    //要用到的命名空间
    using System.Runtime;
    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels;
    using System.Runtime.Remoting.Channels.Tcp;
    
    
    ///实体
    
    public class RemotingLibraryClass
    {
    public RemotingLibraryClass()
    {
        Console.WriteLine("我连接成功");
    }
    public void SetMes(string Str)
    {Console.WriteLine("Hello :"+s);
    }
    }
    
    ///services服务端
    public class UsersServices
    {
    static void Main(){
    TcpServerChannels tcp = new TcpServerChannels(8500);//8500为端口号
    Channels.RegisterChannels(tcp,true)// 这里的true要与客户端的保证一样
    RemotingConfiguration.RegisterWellKnownServerType(typeof(RemotingLibraryClass),"abc",WellKnownObjectMode.SingleCall);
    Console.WriteLing("服务启动成功!");
    Console.ReadKey();
    }
    }
    ////Client客户端
    
    
    public class UsersClient
    {
    static void Main()
    {
    ChannelsServer.RegisterChannels(new TcpClientChannels(),true);
    RemotingLibraryClass obj = (RemotingLibraryClass)Activator.GetObject(typeof(RemotingLibraryClass),"tcp:192.168.1.108:8500/abc");
    if (obj != null)
                {
                    obj.SetMess("张三");
                    Console.WriteLine("服务连接成功");
                }
                else
                { Console.WriteLine("与服务连接失败"); }
               
                Console.ReadKey();}
    }
    
    
    
    
    
    
    
    

  • 相关阅读:
    为什么项目经理非常难有节操的选举
    二叉查找树的删除操作
    二叉查找树的前驱后继
    替罪羊树
    树链剖分
    DFS序
    bzoj3224: Tyvj 1728 普通平衡树(平衡树)
    splay树入门(带3个例题)
    红黑树
    AVL树
  • 原文地址:https://www.cnblogs.com/server126/p/1934129.html
Copyright © 2011-2022 走看看