惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - fanrsh

Javascript's Event 的一点总结 [转]SQL Server2005 SQLCLR代码安全之权限(3) [转]SQL Server2005 SQLCLR代码安全之权限(2) [转]SQL Server2005 SQLCLR代码安全之权限(1) jquery入门1:简单收缩菜单 - fanrsh - 博客园 jQuery工作原理解析以及源代码示例 ASP.NET 页面生存周期概览 推荐一个快速反射调用的类 Visual Studio 2005的版本情况和新特征详细介绍 Creating and writing ASP.NET 2.0 custom Configuration Sections 给大家一个CSS编辑工具,结合JQUERY用的很爽啊 flv视频是如何转的? codesmith学习资源 asp.net 事件验证 CSS循序渐进系列 [更新中]Lucene.net,中文分词技术 ICTCLAS研究 .net sql连接字符串详解 socket专家好文收藏 jQuery学习资源
Remoting事件序列一:客户端触发服务器端事件
fanrsh · 2007-09-14 · via 博客园 - fanrsh

最近常有网友问我关于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();
        }

    }

}

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