今天对C# Remoting进行了初步的学习,废话不说...

RemotingModel: Talker.cs

using System;
using System.Collections.Generic;
using System.Text;
namespace RemotingModel
{
    /// <summary>
    ///
    /// </summary>
   public class Talker:MarshalByRefObject
    {
       /// <summary>
       /// 说话
       /// </summary>
       /// <param name="word"></param>
       public void Talk(string word)
       {
           System.Console.WriteLine(word);
       }
    }
}
服务器端:是一个控制台,首先要添加对System.Runtime.Remoting的引用,然后添加对RemotingModel的引用
using System;
using System.Collections.Generic;
using System.Text;
 
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
 
using RemotingModel;
 
namespace RemotingServer
{
    class Program
    {
        static void Main(string[] args)
        {
            //注册通道
            TcpServerChannel channel = new TcpServerChannel("TalkChannel", 8090); //端口随便取
            ChannelServices.RegisterChannel(channel, true);
 
           //注册远程对象
            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(Talker),
                "Talker",  
               WellKnownObjectMode.SingleCall);
           Console.ReadLine();
        }
    }
}
客服端:窗体:两个textBox,一个button,设置textBox为多行。上面的textBox为:txtContent,下面的为:txtWord
 

添加引用(添加方法同上)
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemotingModel;
namespace RemotingClient
{
    public partial class Form1 : Form
    {
        private Talker _talk = null;
        public Form1()
        {
            InitializeComponent();
        }
       private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                //操作远程对象
                _talk.Talk(txtWord.Text.Trim());
                txtContent.Text = "发送成功" + txtWord.Text.Trim();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
       private void Form1_Load(object sender, EventArgs e)
        {
            try {
                //注册通道
                TcpClientChannel channel = new TcpClientChannel();
                ChannelServices.RegisterChannel(channel, true);
               //获取远程对象
                _talk=(Talker) Activator.GetObject(typeof(Talker),"TCP://localhost:8090/Talker");
            }
            catch(Exception ex){
                MessageBox.Show(ex.Message);
            }
        }
    }
}
好了,下面看看结果:
 

注:以上所有操作均在同一台电脑,并且在同一个解决方案执行。

接下来会跟大家分享Remoting在局域网里的使用

RemoTing 搭建简单实现的更多相关文章

  1. 树莓派(Raspberry Pi)搭建简单的lamp服务

    树莓派(Raspberry Pi)搭建简单的lamp服务: 1. LAMP 的安装 sudo apt-get install apache2 mysql-server mysql-client php ...

  2. 拿nodejs快速搭建简单Oauth认证和restful API server攻略

    拿nodejs快速搭建简单Oauth认证和restful API server攻略:http://blog.csdn.net/zhaoweitco/article/details/21708955 最 ...

  3. Ubuntu 14.04搭建简单git服务器

    /****************************************************************************** * Ubuntu 14.04搭建简单gi ...

  4. 转:windows下使用gvim搭建简单的IDE编译环境(支持C/C++/Python等)

    原文来自于:http://www.cnblogs.com/zhuyp1015/archive/2012/06/16/2552269.html 使用gvim在windows环境下搭建简单的IDE环境可以 ...

  5. [angularjs] MVC + Web API + AngularJs 搭建简单的 CURD 框架

    MVC + Web API + AngularJs 搭建简单的 CURD 框架 GitHub 地址:https://github.com/liqingwen2015/Wen.MvcSinglePage ...

  6. nodejs辅助前台开发系列(1) 搭建简单HTML开发环境

    搭建简单的html开发环境一般需要解决两个问题: 文本编辑器 WebServer集成 在文本编辑器选择上,VS Code 无疑是一匹黑马,谁用谁知道.WebServer集成nodejs对前端来说最为友 ...

  7. mongoDB介绍、安装、搭建简单的mongoDB服务器(一)

    相关网站 1. http://www.mongodb.org/ 官网,可以下载安装程序,和doc,和驱动等. 2. http://www.mongoing.com/ 国内官方网站,博客,问题谈论等  ...

  8. Nginx之使用nginx搭建简单的文件服务器

    使用nginx可以搭建简单文件服务器 安装nginx(不详述) 修改配置文件 /usr/local/nginx/conf/nginx.conf user root; /usr/local/nginx/ ...

  9. 基于python2【重要】怎么自行搭建简单的web服务器

    基本流程:1.需要的支持     1)python本身有SimpleHTTPServer     2)ForkStaticServer.py支持,该文件放在python7目录下     3)将希望共享 ...

随机推荐

  1. size - 列出段节大小和总共大小

    总览 (SYNOPSIS) size [-A|-B|--format=compatibility] [--help] [-d|-o|-x|--radix=number] [--target=bfdna ...

  2. go语言从例子开始之Example14.变参函数

    可变参数函数.可以用任意数量的参数调用.例如,fmt.Println 是一个常见的变参函数. Example: package main import "fmt" //...int ...

  3. Java多线程的理解和实例

    编写具有多线程程序经常会用到的方法:run(), start(), wait(), notify(), notifyAll(), sleep(), yield(), join() 还有一个关键字:sy ...

  4. postgres服务安装,启动和配置

    安装以及启动 yum install readline-devel tar xf postgresql-11.1.tar.gz cd postgresql-11.1 ./configure --pre ...

  5. linux文件查找工具——locate,find

    一文件查找介绍 文件的查找就是在文件系统上查找符合条件的文件. 文件查找的方式:locate, find非实时查找也就是基于数据库查找的locate,效率特别高. 实时查找:find 二locate ...

  6. PHP curl_multi_info_read函数

    curl_multi_info_read — 获取当前解析的cURL的相关传输信息 说明 array curl_multi_info_read ( resource $mh [, int &$ ...

  7. delphi 以系统权限运行程序的代码

    program sysrun; uses Windows, SysUtils, tlhelp32, AccCtrl, AclAPI; function findprocess(TheProcName: ...

  8. (转)使用OpenGL显示图像(二)定义Shapes

    定义形状 编写:jdneo - 原文:http://developer.android.com/training/graphics/opengl/shapes.html 在一个OpenGL ES Vi ...

  9. 2019ccpc秦皇岛/Gym102361 F Forest Program 仙人掌上dfs

    题意: 某地沙漠化严重,沙漠里长了很多仙人掌,现在要让你删掉仙人掌的一些边让它的所有连通分量都是树,就完成了沙漠绿化(什么鬼逻辑?)让你计算删边的方案数. 仙人掌是一种特殊的图,它的每一条边只属于1或 ...

  10. 利用core_pattern实现core文件的配置和管理

    参考:https://xz.aliyun.com/t/1098 这里所说的core_pattern 指的是:/proc/sys/kernel/core_pattern. 我们知道在Linux系统中,如 ...