找传奇、传世资源到传世资源站!

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

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

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

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