欢迎来到传世资源网!
加载中...
正在加载,请耐心等待...
本站为收藏、学习站,如有侵权,请联系管理员删除!

NetMQ 发布/订阅 源码(C# socket连接)

介绍 评论 失效链接反馈

NetMQNetMQ 发布/订阅 源码(C# socket连接) 常用C#方法-第1张NetMQ 发布/订阅 源码(C# socket连接) 常用C#方法-第2张using NetMQ;using NetMQ.Sockets;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading;using System.Windows.Forms;namespace Client{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } PublisherSocket pubSocket; SubscriberSocket subSocket; private void Form1_Load(object sender, EventArgs e) { pubSocket = new PublisherSocket(); pubSocket.Connect("tcp://127.0.0.1:5678"); subSocket = new SubscriberSocket(); subSocket.ReceiveReady = subSocket_ReceiveReady;//这个事件不触发 = = 暂时没有文档参考。。 subSocket.Connect("tcp://127.0.0.1:1234"); subSocket.Subscribe("A"); } void subSocket_ReceiveReady(object sender, NetMQSocketEventArgs e) { MessageBox.Show(string.Format("主题:{0},订阅消息:{1}\r\n", e.Socket.ReceiveFrameString(), e.Socket.ReceiveFrameString())); } private void Publisher() { txt_Received.AppendText(string.Format("主题:{0},发布消息:{1}\r\n", txt_Topic.Text, txt_Message.Text)); pubSocket.SendMoreFrame(txt_Topic.Text).SendFrame(txt_Message.Text); } private void Subscriber() { System.Timers.Timer time = new System.Timers.Timer(); time.Elapsed = time_Elapsed; time.Interval = 100; time.Start(); } void time_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (subSocket.HasIn) MessageBox.Show(string.Format("主题:{0},订阅消息:{1}\r\n", subSocket.ReceiveFrameString(), subSocket.ReceiveFrameString())); } private void button2_Click(object sender, EventArgs e) { Subscriber(); } private void button1_Click(object sender, EventArgs e) { Publisher(); } }}

下载声明:

本站资源均有第三方用户自行上传分享推荐,非本站自制,仅供玩家做交流学习之用!切勿用于商业用途!游戏作品版权归原作者享有,如有版权问题,请附带版权证明至邮件,本平台将应您的要求删除。
相关推荐:

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复