c# remoting 小实例
来源:互联网 发布:神仙水 去痘印 知乎 编辑:程序博客网 时间:2024/05/23 12:34
c# remoting 小实例
////先定义接口
using System;using System.Text;namespace IComm{ /// <summary> /// send messages delegate /// </summary> /// <param name="Ms"></param> public delegate void SendEventHandler(string Ms); public interface ICom { /// <summary> /// send function /// </summary> /// <param name="Ms"></param> /// <returns></returns> void SendMs(string Ms); }}
////obj类
using System;using System.Text;using IComm;namespace RemotingObj{ public class UsersInfo:MarshalByRefObject,ICom { public static event SendEventHandler SendEventArgs; public void SendMs(string Ms) { if (SendEventArgs != null) SendEventArgs(Ms); } public override object InitializeLifetimeService() { return null; } }}
////服务端代码
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime;using System.Runtime.Remoting;using System.Runtime.Remoting.Channels;using System.Runtime.Remoting.Channels.Tcp;using IComm;using RemotingObj;namespace RemotingServer{ public partial class Form1 : Form { public Form1() { InitializeComponent(); this.toolStripStatusLabel1.ForeColor = Color.Red; } private void Form1_Load(object sender, EventArgs e) { try { TcpServerChannel server = new TcpServerChannel(1234); ChannelServices.RegisterChannel(server, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(UsersInfo), "abc", WellKnownObjectMode.SingleCall); RemotingObj.UsersInfo.SendEventArgs += delegate(string s) { this.textBox1.Text = s; }; this.toolStripStatusLabel1.Text = "服务启动成功!"; } catch (Exception ex) { this.toolStripStatusLabel1.Text = ex.Message; } } }}
///客户端
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Runtime;using System.Runtime.Remoting;using System.Runtime.Remoting.Channels;using System.Runtime.Remoting.Channels.Tcp;using System.Text;using System.Windows.Forms;using System.Runtime;using System.Runtime.Remoting;using System.Runtime.Remoting.Channels;using System.Runtime.Remoting.Channels.Tcp;using IComm;using RemotingObj;namespace RemotingClient{ public partial class Form1 : Form { public Form1() { InitializeComponent(); this.toolStripStatusLabel1.ForeColor = Color.Red; } public ICom obj = null; private void Form1_Load(object sender, EventArgs e) { try { ChannelServices.RegisterChannel(new TcpClientChannel(), false); obj = (ICom)Activator.GetObject(typeof(ICom), "tcp://200.1.3.27:1234/abc"); if (obj != null) { this.toolStripStatusLabel1.Text = "与服务器连接成功!"; } } catch (Exception ex) { this.toolStripStatusLabel1.Text = ex.Message; } } private void button1_Click(object sender, EventArgs e) { if (obj != null && !string.IsNullOrEmpty(this.textBox1.Text)) { obj.SendMs(this.textBox1.Text); } } }}
0 0
- c# remoting 小实例
- c# remoting 小实例
- c# remoting 小实例
- remoting实例
- Remoting 实例
- C# remoting
- C# Remoting
- C#采用Remoting实现跨进程调用之代码实例
- .Net Remoting 实例
- .net Remoting简单实例
- .net Remoting简单实例
- .net Remoting简单实例
- Remoting简单实例[]
- Remoting简单实例
- Remoting简单实例
- .Net Remoting 实例
- .Net Remoting 小程序
- c# 经典小编程实例
- JAVA 接口的应用
- HDU 2845 Beans
- vc读取文件,修改写入,保存文件
- jquery ajax 传数据到后台乱码的处理方法
- 集体智慧编程学习笔记--搜索引擎
- c# remoting 小实例
- The command ("dfs.browser.action.delete") is undefined 解决Hadoop Eclipse插件报错
- c# 反射---简单小例子
- java实现 SSL双向认证
- jQuery、prototype、mootools、YUI Extjs 框架比较
- Chessboard(二分匹配)
- IntelliJ IDEA 14 值得你弃用Eclipse的IDE神器
- MacStore更新Xcode时提示帐户不对,更换帐户方法
- 一键安装Redmine