最近常有网友问我关于Remoting事件的问题,我也正好有些时间,于是决定写两篇关于Remoting事件的入门随笔,希望对新手有所帮助..谢谢

随笔一:客户端触发服务器端事件

通讯类:

using System;
using System.Collections; 
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;

using System.Runtime.Serialization.Formatters; 

namespace RemotingSamples 
{

    public class Server
    {
        public static void Main(string [] args) 
        {

            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;  

            IDictionary props=new Hashtable(); 
            props["port"]=8085;  

            TcpChannel chan1 = new TcpChannel(props,clientProvider,serverProvider);


            ChannelServices.RegisterChannel(chan1);



            RemotingConfiguration.RegisterWellKnownServiceType
                (
                typeof(HelloServer),
                "SayHello",
                WellKnownObjectMode.Singleton
                );


            

            System.Console.WriteLine("Press Enter key to exit");
            System.Console.ReadLine();

        }

    }
}

服务器端代码:

using System;
using System.Collections; 
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;

using System.Runtime.Serialization.Formatters; 

namespace RemotingSamples 
{

    public class Server
    {
        public static void Main(string [] args) 
        {

            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;  

            IDictionary props=new Hashtable(); 
            props["port"]=8085;  

            TcpChannel chan1 = new TcpChannel(props,clientProvider,serverProvider);


            ChannelServices.RegisterChannel(chan1);



            RemotingConfiguration.RegisterWellKnownServiceType
                (
                typeof(HelloServer),
                "SayHello",
                WellKnownObjectMode.Singleton
                );


            

            System.Console.WriteLine("Press Enter key to exit");
            System.Console.ReadLine();

        }

    }
}

客户端代码:

using System;
using System.Collections; 
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.IO;
using System.Runtime.Serialization.Formatters; 

namespace RemotingSamples 
{
    public class Client
    {
        public static void Main(string[] args)
        {

            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;  
            //使用TCP通道得到远程对象
            IDictionary props = new Hashtable();
            props["port"] = 0;
            TcpChannel chan1 = new TcpChannel(props, clientProvider, serverProvider);
            ChannelServices.RegisterChannel(chan1);
            HelloServer obj1 = (HelloServer)Activator.GetObject(
                typeof(RemotingSamples.HelloServer),
                "tcp://localhost:8085/SayHello");
            if (obj1 == null)
            {
                System.Console.WriteLine(
                    "Could not locate TCP server");
            }


            obj1.myevent += new MyEventHandler(obj1.eventmethod);


            Console.WriteLine(
                "Client1 TCP HelloMethod {0}",
                obj1.HelloMethod("Caveman1"));

            Console.ReadLine();
        }
    }
}

代码很简单,我就不做描述了,有问题直接留言,我会尽快做出回复..

转载于:https://www.cnblogs.com/fanrsh/archive/2007/09/14/893315.html

Remoting事件序列一:客户端触发服务器端事件相关推荐

  1. 触发dblclick事件时,避免触发click事件-实例

    正常情况下触发双击dblclick事件时会同时触发两遍单击click事件,这肯定不是我们想要的结果,那么如何避免伴随触发click事件呢? 浏览器监听双击事件的机制是,有没有在一定时间内监听到两次连续 ...

  2. 页面回传与js调用服务器端事件(转)

    第一章. Asp.net中服务端控件事件是如何触发的 Asp.net 中在客户端触发服务器端事件分为两种情况: 一.   WebControls中的Button 和HtmlControls中的Type ...

  3. WPF 触屏事件后触发鼠标事件的问题及 DataGrid 误触问题

    WPF 触屏事件后触发鼠标事件的问题及 DataGrid 误触问题 目录 一.触屏事件连带触发鼠标事件的问题 二.DataGrid 误触问题及解决方法 独立观察员 2021 年 10 月 10 日 一 ...

  4. js第8章事件案例:获取触发事件的元素,阻止事件冒泡和默认行为的实现、缓动的小球、图片放大特效、按Enter键切换

    目录 1.获取触发事件的元素,阻止事件冒泡和默认行为的实现. (1)获取触发事件的元素 (2)阻止事件冒泡 (3)阻止事件默认行为 2.缓动的小球,实现的原理是通过定时器连续地修改当前DOM元素的某个 ...

  5. 如何通过JQuery动态触发oninput事件

    众所周知,如果想到实时监听input框值的改变可以通过监听input事件完成,例如: let $input = $("#input"); $input.on("input ...

  6. 六十二、Js中的冒泡和捕获点击事件和Vue组件绑定原生事件

    2020/10/18 . 周日.今天又是奋斗的一天. @Author:Runsen @Date:2020/10/18 写在前面:我是「Runsen」,热爱技术.热爱开源.热爱编程.技术是开源的.知识是 ...

  7. qgraphicsitem鼠标移动事件阻塞_常用的DOM事件

    用户界面事件:当用户与页面的上的元素交互时发生,但不一定与用户操作有关的事件. load事件:当页面加载完毕时在window上触发,当图像加载完毕时在ing元素上触发,等等,页面完全加载完毕(包括所有 ...

  8. wpf 监听退出事件_WPF中常用的Window事件

    1. Activated获得焦点事件 和 Deactivated失去焦点的事件: Activated: 获得焦点 (首次打开软件时:由别的软件切换回当前软件时:点击当前软件在任务栏的按钮时) Deac ...

  9. Vue input的blur事件影响下拉框中点击事件的解决方案 用mousedown/mousedown替代click

    最近遇到一个需求,输入框输入关键词,要出一个带输入建议的弹框,类似于ElementUI自带的<el-autocomplete>,只是需求中的弹框底部有个分页功能,因此用不了自带的<e ...

  10. 重写render,利用ClientScript,在客户端注册select,回发到服务器,触发服务器端的行选择事件。...

    View Code 原文地址 http://edu.cnzz.cn/NewsInfo/28278.aspx#  1     //重写render,利用ClientScript,在客户端注册select ...

最新文章

  1. 为什么要使用main函数
  2. Latex常用数学符号
  3. MyBatis映射文件(二)
  4. .NET Core开发实战(第33课:集成事件:使用RabbitMQ来实现EventBus)--学习笔记(下)...
  5. 线性代数基础(矩阵、范数、正交、特征值分解、奇异值分解、迹运算)
  6. 高级函数技巧-函数柯里化
  7. angular学习资源
  8. The Maven Integration requires that Eclipse be running in a JDK……
  9. bin文件转换成html,bin如何改成mp4
  10. java cms 源码_PublicCMS开源Java系统 v4.0.190312
  11. opencv之银行卡号识别
  12. python学习笔记11 百度识图
  13. python 中的拷贝、浅拷贝与深拷贝
  14. SiamRPN代码分析:training
  15. 新浪微博分享遇到的心酸的问题
  16. 【概率】甲乙射击比赛,单局甲胜率0.6,3局2胜和5局3胜两种赛制甲如何选择?无限多局,甲获胜概率?
  17. 神经网络编程的34个案例,神经网络程序实例100篇
  18. Windows 无法打开“添加打印机”。本地打印后台处理程序服务没有运行。请重新启动打印机后台处理程序或重新启动计算机。...
  19. android蓝牙开启的通知,在Android(蓝牙低功耗)中启用蓝牙特性通知不起作用
  20. shiny教程一 -- shiny入门

热门文章

  1. 大数据体系的4个热点4个趋势,还有3个疑问
  2. 易华录数据湖事业部安全中心招聘中高级安全工程师2-4人
  3. 【图像去雾】基于matlab直方图+retinex+暗通道图像去雾【含Matlab源码 074期】
  4. 【图像计数】基于matlab灰度二值化同类物体简单计数【含Matlab源码 759期】
  5. 【图像融合】基于matlab IHS图像融合【含Matlab源码 724期】
  6. 【优化覆盖】基于matlab GUI粒子群算法求解传感器覆盖优化问题【含Matlab源码 709期】
  7. 【元胞自动机】基于matlab元胞自动机求解城市小区开放对周边道路通行影响研究【含Matlab源码 233期】
  8. 中间表为什么可以不用实体类_法国蜗牛供不应求,为什么不用中国蜗牛代替?看完才知道真不可以...
  9. 数据排序pandas
  10. 例2.3 日期差值 - 九度教程第6题(日期类问题)