.Net中Remoting通信机制简单实例
2016-11-29 23:24
330 查看
.Net中Remoting通信机制
前言:
本程序例子实现一个简单的Remoting通信案例
本程序采用语言:c#
编译工具:vs2013工程文件
编译环境:.net 4.0
程序模块:
- Test测试
- Talker
- Server端
- Client端
- 源代码工程文件下载
Test测试程序截图:
Talker类:
public class Talker : MarshalByRefObject { public void Talk(string word) { System.Console.WriteLine(word); } }
Server端:
//注册通道 TcpServerChannel channel = new TcpServerChannel("TalkChannel",8090); ChannelServices.RegisterChannel(channel,true); //注册远程对象 RemotingConfiguration.RegisterWellKnownServiceType( typeof(Talker), "Talker", WellKnownObjectMode.SingleCall);
Client端:
public partial class Form1 : Form { private Talker _talk = null; public Form1() { InitializeComponent(); } private void btnSend_Click(object sender, EventArgs e) { if (btnSend.Text.Equals("开始")) { timer1.Enabled = true; btnSend.Text = "结束"; } else { timer1.Enabled = false; btnSend.Text = "开始"; } } private void sendMsg(string msg) { try { //操作远程对象 _talk.Talk(msg); string newline = msg + Environment.NewLine; txtContent.Text = txtContent.Text.Insert(0, newline); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Form1_Load(object sender, EventArgs e) { try { timer1.Interval = 1000; //注册通道 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); } } private void timer1_Tick(object sender, EventArgs e) { sendMsg(txtWord.Text.Trim()); }
源代码工程文件下载:
源代码工程文件下载 http://files.cnblogs.com/files/JiYF/RemotingSolution.rar
相关文章推荐
- .Net中Remoting通信机制简单实例
- .net Remoting简单实例
- .NET的插件机制的简单实现
- .NET 异常捕获机制的小技巧应用(实例:端口扫描程序)
- Remoting简单实例[]
- .net与java webService通信的最简单方法
- Remoting简单实例
- .Net Remoting 实例
- FLASH与JS通信简单实例
- .Net Remoting 实例
- .net Remoting简单实例
- .net中post上传的简单实例
- .net页面间的参数传递简单实例
- .net页面间的参数传递简单实例
- .net页面间的参数传递简单实例
- .net页面间的参数传递简单实例
- 简单了解.NET中的动态编译机制
- 关于.Net Remoting 的一个简单示例
- Remoting技术初探--实现简单服务器客户机通信
- 简单适用的 .NET 事件实例代码