Romoting 通信DEMO(整理)
来源:互联网 发布:js中字符串的几种方法 编辑:程序博客网 时间:2024/06/09 13:48
1、服务端
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using GeneralService;
namespace RemotingServer
{
public class Server
{
public static int Main(string[] args)
{
//TCP协议传输消息的信道实现
TcpChannel chan1 = new TcpChannel(8085);
//为远程调用实现使用HTTP协议传输消息的客户端通道
HttpChannel chan2 = new HttpChannel(8086);
//提供帮助进行远程处理信道注册、解析和URL发现的静态方法。无法继承此类
ChannelServices.RegisterChannel(chan1, false);
ChannelServices.RegisterChannel(chan2,false);
//提供多种配置远程结构的静态方法
RemotingConfiguration.RegisterWellKnownServiceType
(
typeof(HelloServer),
"SayHello",
WellKnownObjectMode.Singleton
);
System.Console.WriteLine("Press Enter key to exit");
System.Console.ReadLine();
return 0;
}
}
}
2、服务类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace GeneralService
{
public class HelloServer : MarshalByRefObject
{
public HelloServer()
{
Console.WriteLine("HelloServer activated");
}public String HelloMethod(String name)
{
Console.WriteLine(
"Server Hello.HelloMethod : {0}", name);
return "Hi there " + name;
}
}}
3、客户端
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using GeneralService;namespace RemotingClient
{
public class Client
{
public static void Main(string[] args)
{
//使用TCP通道得到远程对象
TcpChannel chan1 = new TcpChannel();
ChannelServices.RegisterChannel(chan1,false);
//Activator包含特定的方法,用以在本地或从远程创建对象类型、或获取对现有远程对象的引用。无法继承此类
HelloServer obj1 = (HelloServer)Activator.GetObject(
typeof(GeneralService.HelloServer),
"tcp://localhost:8085/SayHello");
if (obj1 == null)
{
System.Console.WriteLine(
"Could not locate TCP server");
}
//使用HTTP通道得到远程对象
HttpChannel chan2 = new HttpChannel();
ChannelServices.RegisterChannel(chan2,false);
HelloServer obj2 = (HelloServer)Activator.GetObject(
typeof(GeneralService.HelloServer),
"http://localhost:8086/SayHello");
if (obj2 == null)
{
System.Console.WriteLine(
"Could not locate HTTP server");
}Console.WriteLine(
"Client1 TCP HelloMethod {0}",
obj1.HelloMethod("Caveman1"));
Console.WriteLine(
"Client2 HTTP HelloMethod {0}",
obj2.HelloMethod("Caveman2"));
Console.ReadLine();
}
}
}
- Romoting 通信DEMO(整理)
- Microsoft .NET Romoting 框架简介(摘自MSDN)
- Microsoft .NET Romoting 框架简介(摘自MSDN)
- romoting简介
- demo 整理
- ESFramework Demo -- P2P通信Demo(附源码)
- ESFramework Demo -- P2P通信Demo(附源码)
- Socket(UDP)通信winform demo
- .NET Romoting 学习总结(一)——Remoting技术之激活模式全接触
- .NET Romoting 学习总结(二)—— Remoting技术之远程调用三步走
- .NET Romoting 学习总结(三)—— Remoting技术之设计模式实现代码安全
- .NET Romoting 学习总结(四)—— Remoting技术细节之多通道注册
- 关于Romoting又一例
- Udp实现通信DEMO
- [android]网络通信demo
- 客户端服务器通信demo
- 串口通信Demo
- Java socket通信Demo
- Maven概述(非原创)
- C# base和this(非原创)
- 用凭据管理器提升Windows7访问速度(非原创)
- J2EE导入代码注释规范
- J2EE系统开发环境配置
- Romoting 通信DEMO(整理)
- IT项目管理理论系列一
- ASP.NET MVC 拦截器(转)
- System.Web.Routing 路由功能详解(整理版)
- C# 缓存介绍与演示(转)
- 依赖注入容器Unity Application Block快速入门(整理更新版,非原创)
- sql server 2005中表的数据与excel互相导入导出的方法
- IEC870-05-104 传输规约(国电)
- 实时数据库介绍(转载)