Romoting 通信DEMO(整理)
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();
}
}
}
转载于:https://www.cnblogs.com/GeneralXU/archive/2010/01/26/1656464.html
Romoting 通信DEMO(整理)相关推荐
- 【安卓SDK学习之anyChatSDK】 1_1 实现用户登录和房间进出(根据官方HelloAnyChat的demo整理的简要的开发流程)
AnyChat SDK是一套多媒体即时通讯平台库,只需要几个简单的API调用,即可实现多个用户之间的语音.视频.文字交互.AnyChat支持"一对一"."一对多" ...
- VC++ 6.0 C8051F340 USB PC侧通信 Demo
// HelloWorld.cpp : Defines the entry point for the console application. // /*********************** ...
- 死锁Demo、线程通信Demo
死锁Demo(一人拿到一个资源,相互等待对方释放资源,解决方法别在一个同步代码块中再写一个同步代码块应该使它们同级): package com.kuang;public class DeathLock ...
- 客户端服务器通信demo(续) -- 使用二进制协议 (附源码)
转载连接: http://blog.csdn.net/zhuweisky/article/details/11827797 在网络上,交互的双方基于TCP或UDP进行通信,通信协议的格式通常分为两类: ...
- 简单双机通信java_完整版)51单片机实现双机通信(自己整理的
<完整版)51单片机实现双机通信(自己整理的>由会员分享,可在线阅读,更多相关<完整版)51单片机实现双机通信(自己整理的(6页珍藏版)>请在人人文库网上搜索. 1.PjfAl ...
- PHP socket多路复用通信demo
PHP socket多路复用通信demo server.php 服务端脚本 function server() {date_default_timezone_set('PRC'); //设置时区set ...
- Google官网开源串口通信Demo
谷歌官方提供了android-serialport-api程序,用于实现串口通信. 谷歌官方源码: https://code.google.com/archive/p/android-serialpo ...
- 关于w600的hspi通信demo
sdk所带的demo中,有一个叫做wm_slave_spi_demo的示例,演示了w600作为从设备时与stm32单片机进行高速spi进入通信的过程:其中doc下的demo使用文档中一处错误需要注意, ...
- ESFramework Demo -- P2P通信Demo(附源码)
现在我们将在ESFramework Demo -- 文件传送Demo 的基础上,使用ESPlus提供的第四个武器,为其增加P2P通信的功能.在阅读本文之前,请务必先掌握ESFramework 开发手册 ...
最新文章
- Map-Reduce和分片集合
- import是引进外部函数吗_你必须要知道的Python中的main函数
- [Swift]LeetCode934. 最短的桥 | Shortest Bridge
- 为什么要进行透明计算和透明计算是什么
- 【数据科学系统学习】机器学习算法 # 西瓜书学习记录 [12] 集成学习实践
- Maven的单元测试插件maven-surefire-plugin详解
- 为什么Facebook的API以一个循环作为开头?
- JAVA对接支付宝支付(超详细,一看就懂)
- 不要为了“分库分表”而“分库分表”
- Maven自动压缩脚本 和 样式文件配置
- 考研英语近义词与反义词·十四·总篇
- java中怎样显示图片_[Java教程]Java中显示图片的方法
- php apm,apm是什么?
- 【心情随笔】2021年终总结
- 自动控制原理7.7---离散系统的数字校正
- 终于又可以用WLW了.
- android http下载限速,Http文件下载、限速、断点续传
- ZZULIOJ 2131 Can Win【思维建图+最大流】
- JavaScript 取随机数
- Spring原码讲解
热门文章
- mysql 高并发 优惠券_转 mysql处理高并发,防止库存超卖
- vue当前页引入js_「vue基础」新手入门导航(一)
- java书籍_2020年java从入门到进阶书籍推荐,基础\自学\编程\数据结构\后端\虚拟机\网络\设计模式书籍...
- 库克协议CTO:加密货币有望成为法定货币替代金融工具
- 摩根溪创始人:Coinbase应该购买纽约证券交易所
- 如何设计一道优雅的白名单策略
- 反欺诈埋点的这些页面,风控人都应知悉
- Teradata 金融数据模型FS-LDM
- 洛谷 4364 [九省联考2018]IIIDX
- ARMV8 datasheet学习笔记3:AArch64应用级体系结构之Memory order