Closed meraydin closed 10 years ago
You can use the monitor directly or from Poller, anyway take a look at the tests: https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/MonitorPollTests.cs
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/PollerTests.cs
On Mon, Aug 26, 2013 at 2:45 PM, meraydin notifications@github.com wrote:
I suppose this class is responsible for socket_connected, socket_disconnected, v.s. events. Is there any sample code about how to use this in a PUB/SUB model? (I'm looking for subscriber connected, disconnected events)
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97 .
Hi Doron,
Thanks for the reply. I was trying to find my way on those samples ☹ I suppose I can use this with Publisher socket type too, am I right?
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:28 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
You can use the monitor directly or from Poller, anyway take a look at the tests: https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/MonitorPollTests.cs
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/PollerTests.cs
On Mon, Aug 26, 2013 at 2:45 PM, meraydin notifications@github.com<mailto:notifications@github.com> wrote:
I suppose this class is responsible for socket_connected, socket_disconnected, v.s. events. Is there any sample code about how to use this in a PUB/SUB model? (I'm looking for subscriber connected, disconnected events)
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97 .
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-23259052.
Yes of course.
On Mon, Aug 26, 2013 at 3:33 PM, meraydin notifications@github.com wrote:
Hi Doron,
Thanks for the reply. I was trying to find my way on those samples ☹ I suppose I can use this with Publisher socket type too, am I right?
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:28 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
You can use the monitor directly or from Poller, anyway take a look at the tests:
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/MonitorPollTests.cs
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/PollerTests.cs
On Mon, Aug 26, 2013 at 2:45 PM, meraydin <notifications@github.com mailto:notifications@github.com> wrote:
I suppose this class is responsible for socket_connected, socket_disconnected, v.s. events. Is there any sample code about how to use this in a PUB/SUB model? (I'm looking for subscriber connected, disconnected events)
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23259052>.
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-23259289 .
Here is the sample code I’ve come up... You can publish it somewhere if you wish... Just one more thing... How can I use this from another event? Let’s say a timer ticks and I want to send something to all subscribers... what is the safest way?
using System; using System.Threading.Tasks; using System.Threading; using NetMQ; using NetMQ.Monitoring; using NetMQ.zmq;
namespace Publisher { class Program { static void Main(string[] args) { using (NetMQContext context = NetMQContext.Create()) { Task serverTask = Task.Factory.StartNew(() => Server(context)); Task.WaitAll(serverTask); } }
static void Server(NetMQContext context)
{
using (var pub = context.CreatePublisherSocket())
{
using (NetMQMonitor monitor = new NetMQMonitor(context, pub, "inproc://pub.inproc", SocketEvent.Accepted | SocketEvent.Listening | SocketEvent.Disconnected ))
{
// for publisher/subscriber mode, only the following events happen
monitor.Accepted += new EventHandler<NetMQMonitorSocketEventArgs>(monitor_Accepted);
monitor.Listening += new EventHandler<NetMQMonitorSocketEventArgs>(monitor_Listening);
monitor.Disconnected += new EventHandler<NetMQMonitorSocketEventArgs>(monitor_Disconnected);
monitor.Timeout = TimeSpan.FromMilliseconds(100);
// be careful with the event handlers, if an exception is thrown, monitor will die!
var pollerTask = Task.Factory.StartNew(monitor.Start);
// publisher uses 'bind' (subscriber uses 'connect')
pub.Bind("tcp://*:5002");
pub.Options.DelayAttachOnConnect = false;
for (int i = 0; i < 1000; i++)
{
pub.Send("Hello" + i.ToString());
Thread.Sleep(25);
}
}
}
}
static void monitor_Disconnected(object sender, NetMQMonitorSocketEventArgs e)
{
Console.WriteLine("Disconnected: " + e.Socket.RemoteEndPoint.ToString());
}
static void monitor_Listening(object sender, NetMQMonitorSocketEventArgs e)
{
Console.WriteLine("Listening on: " + e.Socket.LocalEndPoint.ToString());
}
static void monitor_Accepted(object sender, NetMQMonitorSocketEventArgs e)
{
Console.WriteLine("Accepted: " + e.Socket.RemoteEndPoint.ToString());
}
}
}
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:55 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
Yes of course.
On Mon, Aug 26, 2013 at 3:33 PM, meraydin notifications@github.com<mailto:notifications@github.com> wrote:
Hi Doron,
Thanks for the reply. I was trying to find my way on those samples ☹ I suppose I can use this with Publisher socket type too, am I right?
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:28 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
You can use the monitor directly or from Poller, anyway take a look at the tests:
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/MonitorPollTests.cs
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/PollerTests.cs
On Mon, Aug 26, 2013 at 2:45 PM, meraydin <notifications@github.com mailto:notifications@github.com%20%0b> mailto:notifications@github.com> wrote:
I suppose this class is responsible for socket_connected, socket_disconnected, v.s. events. Is there any sample code about how to use this in a PUB/SUB model? (I'm looking for subscriber connected, disconnected events)
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23259052>.
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-23259289 .
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-23260390.
To use timer with monitoring take a look at the poller class, I sent you the link in the last email. On Aug 26, 2013 4:18 PM, "meraydin" notifications@github.com wrote:
Here is the sample code I’ve come up... You can publish it somewhere if you wish... Just one more thing... How can I use this from another event? Let’s say a timer ticks and I want to send something to all subscribers... what is the safest way?
using System; using System.Threading.Tasks; using System.Threading; using NetMQ; using NetMQ.Monitoring; using NetMQ.zmq;
namespace Publisher { class Program { static void Main(string[] args) { using (NetMQContext context = NetMQContext.Create()) { Task serverTask = Task.Factory.StartNew(() => Server(context)); Task.WaitAll(serverTask); } }
static void Server(NetMQContext context) { using (var pub = context.CreatePublisherSocket()) { using (NetMQMonitor monitor = new NetMQMonitor(context, pub, "inproc://pub.inproc", SocketEvent.Accepted | SocketEvent.Listening | SocketEvent.Disconnected )) { // for publisher/subscriber mode, only the following events happen monitor.Accepted += new EventHandler
(monitor_Accepted); monitor.Listening += new EventHandler (monitor_Listening); monitor.Disconnected += new EventHandler (monitor_Disconnected); monitor.Timeout = TimeSpan.FromMilliseconds(100);
// be careful with the event handlers, if an exception is thrown, monitor will die! var pollerTask = Task.Factory.StartNew(monitor.Start);
// publisher uses 'bind' (subscriber uses 'connect') pub.Bind("tcp://*:5002"); pub.Options.DelayAttachOnConnect = false;
for (int i = 0; i < 1000; i++) { pub.Send("Hello" + i.ToString()); Thread.Sleep(25); } } } }
static void monitor_Disconnected(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Disconnected: " + e.Socket.RemoteEndPoint.ToString()); }
static void monitor_Listening(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Listening on: " + e.Socket.LocalEndPoint.ToString()); }
static void monitor_Accepted(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Accepted: " + e.Socket.RemoteEndPoint.ToString()); } } }
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:55 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
Yes of course.
On Mon, Aug 26, 2013 at 3:33 PM, meraydin <notifications@github.com mailto:notifications@github.com> wrote:
Hi Doron,
Thanks for the reply. I was trying to find my way on those samples ☹ I suppose I can use this with Publisher socket type too, am I right?
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:28 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
You can use the monitor directly or from Poller, anyway take a look at the tests:
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/MonitorPollTests.cs
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/PollerTests.cs
On Mon, Aug 26, 2013 at 2:45 PM, meraydin <notifications@github.com mailto:notifications@github.com%20%0b> mailto:notifications@github.com> wrote:
I suppose this class is responsible for socket_connected, socket_disconnected, v.s. events. Is there any sample code about how to use this in a PUB/SUB model? (I'm looking for subscriber connected, disconnected events)
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23259052>.
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23259289> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23260390>.
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-23261569 .
I meant the timers.ttimer class... actually i want to subscribe to eventlog events and on logEntryWritten event I want to send them to subscribers. But 'using' blocks scares me. That's why i asked for a timer.tick sample so that i can convert that code.
Sent from Samsung Mobile
-------- Original message -------- From: Doron Somech notifications@github.com Date: To: zeromq/netmq netmq@noreply.github.com Cc: Murat Eraydın murat.eraydin@karmasis.com Subject: Re: [netmq] NetMQMonitor sample (#97)
To use timer with monitoring take a look at the poller class, I sent you the link in the last email. On Aug 26, 2013 4:18 PM, "meraydin" notifications@github.com wrote:
Here is the sample code I’ve come up... You can publish it somewhere if you wish... Just one more thing... How can I use this from another event? Let’s say a timer ticks and I want to send something to all subscribers... what is the safest way?
using System; using System.Threading.Tasks; using System.Threading; using NetMQ; using NetMQ.Monitoring; using NetMQ.zmq;
namespace Publisher { class Program { static void Main(string[] args) { using (NetMQContext context = NetMQContext.Create()) { Task serverTask = Task.Factory.StartNew(() => Server(context)); Task.WaitAll(serverTask); } }
static void Server(NetMQContext context) { using (var pub = context.CreatePublisherSocket()) { using (NetMQMonitor monitor = new NetMQMonitor(context, pub, "inproc://pub.inproc", SocketEvent.Accepted | SocketEvent.Listening | SocketEvent.Disconnected )) { // for publisher/subscriber mode, only the following events happen monitor.Accepted += new EventHandler
(monitor_Accepted); monitor.Listening += new EventHandler (monitor_Listening); monitor.Disconnected += new EventHandler (monitor_Disconnected); monitor.Timeout = TimeSpan.FromMilliseconds(100);
// be careful with the event handlers, if an exception is thrown, monitor will die! var pollerTask = Task.Factory.StartNew(monitor.Start);
// publisher uses 'bind' (subscriber uses 'connect') pub.Bind("tcp://*:5002"); pub.Options.DelayAttachOnConnect = false;
for (int i = 0; i < 1000; i++) { pub.Send("Hello" + i.ToString()); Thread.Sleep(25); } } } }
static void monitor_Disconnected(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Disconnected: " + e.Socket.RemoteEndPoint.ToString()); }
static void monitor_Listening(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Listening on: " + e.Socket.LocalEndPoint.ToString()); }
static void monitor_Accepted(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Accepted: " + e.Socket.RemoteEndPoint.ToString()); } } }
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:55 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
Yes of course.
On Mon, Aug 26, 2013 at 3:33 PM, meraydin <notifications@github.com mailto:notifications@github.com> wrote:
Hi Doron,
Thanks for the reply. I was trying to find my way on those samples ☹ I suppose I can use this with Publisher socket type too, am I right?
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:28 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
You can use the monitor directly or from Poller, anyway take a look at the tests:
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/MonitorPollTests.cs
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/PollerTests.cs
On Mon, Aug 26, 2013 at 2:45 PM, meraydin <notifications@github.com mailto:notifications@github.com%20%0b> mailto:notifications@github.com> wrote:
I suppose this class is responsible for socket_connected, socket_disconnected, v.s. events. Is there any sample code about how to use this in a PUB/SUB model? (I'm looking for subscriber connected, disconnected events)
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23259052>.
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23259289> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23260390>.
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-23261569 .
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-23284476.
To be more precise here is the code block I want to use NetMQ’s Publisher:
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics;
namespace EventLogTest { class Program { static void Main(string[] args) { EventLog log = new EventLog("System"); log.EntryWritten += new EntryWrittenEventHandler(log_EntryWritten); log.EnableRaisingEvents = true; Console.WriteLine("Press ENTER to exit"); Console.ReadLine(); }
static void log_EntryWritten(object sender, EntryWrittenEventArgs e)
{
Console.WriteLine(e.Entry.Message);
//how can I send e.Entry.Message to all subscribers?
//should I initialize the context and PublisherSocket globally or
//use a 'using' block here?
}
}
}
From: Murat Eraydın Sent: 26 Ağustos 2013 Pazartesi 22:37 To: reply@reply.github.com; netmq@noreply.github.com Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
I meant the timers.ttimer class... actually i want to subscribe to eventlog events and on logEntryWritten event I want to send them to subscribers. But 'using' blocks scares me. That's why i asked for a timer.tick sample so that i can convert that code.
Sent from Samsung Mobile
-------- Original message -------- From: Doron Somech notifications@github.com<mailto:notifications@github.com> Date: To: zeromq/netmq netmq@noreply.github.com<mailto:netmq@noreply.github.com> Cc: Murat Eraydın murat.eraydin@karmasis.com<mailto:murat.eraydin@karmasis.com> Subject: Re: [netmq] NetMQMonitor sample (#97)
To use timer with monitoring take a look at the poller class, I sent you the link in the last email. On Aug 26, 2013 4:18 PM, "meraydin" notifications@github.com<mailto:notifications@github.com> wrote:
Here is the sample code I’ve come up... You can publish it somewhere if you wish... Just one more thing... How can I use this from another event? Let’s say a timer ticks and I want to send something to all subscribers... what is the safest way?
using System; using System.Threading.Tasks; using System.Threading; using NetMQ; using NetMQ.Monitoring; using NetMQ.zmq;
namespace Publisher { class Program { static void Main(string[] args) { using (NetMQContext context = NetMQContext.Create()) { Task serverTask = Task.Factory.StartNew(() => Server(context)); Task.WaitAll(serverTask); } }
static void Server(NetMQContext context) { using (var pub = context.CreatePublisherSocket()) { using (NetMQMonitor monitor = new NetMQMonitor(context, pub, "inproc://pub.inproc", SocketEvent.Accepted | SocketEvent.Listening | SocketEvent.Disconnected )) { // for publisher/subscriber mode, only the following events happen monitor.Accepted += new EventHandler
(monitor_Accepted); monitor.Listening += new EventHandler (monitor_Listening); monitor.Disconnected += new EventHandler (monitor_Disconnected); monitor.Timeout = TimeSpan.FromMilliseconds(100);
// be careful with the event handlers, if an exception is thrown, monitor will die! var pollerTask = Task.Factory.StartNew(monitor.Start);
// publisher uses 'bind' (subscriber uses 'connect') pub.Bind("tcp://*:5002"); pub.Options.DelayAttachOnConnect = false;
for (int i = 0; i < 1000; i++) { pub.Send("Hello" + i.ToString()); Thread.Sleep(25); } } } }
static void monitor_Disconnected(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Disconnected: " + e.Socket.RemoteEndPoint.ToString()); }
static void monitor_Listening(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Listening on: " + e.Socket.LocalEndPoint.ToString()); }
static void monitor_Accepted(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Accepted: " + e.Socket.RemoteEndPoint.ToString()); } } }
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:55 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
Yes of course.
On Mon, Aug 26, 2013 at 3:33 PM, meraydin <notifications@github.com mailto:notifications@github.com%20%0b> mailto:notifications@github.com> wrote:
Hi Doron,
Thanks for the reply. I was trying to find my way on those samples ☹ I suppose I can use this with Publisher socket type too, am I right?
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:28 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
You can use the monitor directly or from Poller, anyway take a look at the tests:
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/MonitorPollTests.cs
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/PollerTests.cs
On Mon, Aug 26, 2013 at 2:45 PM, meraydin <notifications@github.com mailto:notifications@github.com%20%0b> mailto:notifications@github.com%20%0b> mailto:notifications@github.com> wrote:
I suppose this class is responsible for socket_connected, socket_disconnected, v.s. events. Is there any sample code about how to use this in a PUB/SUB model? (I'm looking for subscriber connected, disconnected events)
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23259052>.
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23259289> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23260390>.
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-23261569 .
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-23284476.
actually you should create the context and the publisher in the main function, the only issue is that you don't know on what thread the event run, Socket is not thread safe, you can lock on it in the event and then call send, but it might suffer from performance if you have a lot of events, if not (let's say less then 500 a second), you can go with the lock solution.
On Mon, Aug 26, 2013 at 11:47 PM, meraydin notifications@github.com wrote:
To be more precise here is the code block I want to use NetMQ’s Publisher:
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics;
namespace EventLogTest { class Program { static void Main(string[] args) { EventLog log = new EventLog("System"); log.EntryWritten += new EntryWrittenEventHandler(log_EntryWritten); log.EnableRaisingEvents = true; Console.WriteLine("Press ENTER to exit"); Console.ReadLine(); }
static void log_EntryWritten(object sender, EntryWrittenEventArgs e) { Console.WriteLine(e.Entry.Message); //how can I send e.Entry.Message to all subscribers? //should I initialize the context and PublisherSocket globally or //use a 'using' block here? } } }
From: Murat Eraydın Sent: 26 Ağustos 2013 Pazartesi 22:37 To: reply@reply.github.com; netmq@noreply.github.com Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
I meant the timers.ttimer class... actually i want to subscribe to eventlog events and on logEntryWritten event I want to send them to subscribers. But 'using' blocks scares me. That's why i asked for a timer.tick sample so that i can convert that code.
Sent from Samsung Mobile
-------- Original message -------- From: Doron Somech <notifications@github.com<mailto: notifications@github.com>> Date: To: zeromq/netmq netmq@noreply.github.com<mailto:netmq@noreply.github.com>
Cc: Murat Eraydın <murat.eraydin@karmasis.com<mailto: murat.eraydin@karmasis.com>> Subject: Re: [netmq] NetMQMonitor sample (#97)
To use timer with monitoring take a look at the poller class, I sent you the link in the last email. On Aug 26, 2013 4:18 PM, "meraydin" <notifications@github.com<mailto: notifications@github.com>> wrote:
Here is the sample code I’ve come up... You can publish it somewhere if you wish... Just one more thing... How can I use this from another event? Let’s say a timer ticks and I want to send something to all subscribers... what is the safest way?
using System; using System.Threading.Tasks; using System.Threading; using NetMQ; using NetMQ.Monitoring; using NetMQ.zmq;
namespace Publisher { class Program { static void Main(string[] args) { using (NetMQContext context = NetMQContext.Create()) { Task serverTask = Task.Factory.StartNew(() => Server(context)); Task.WaitAll(serverTask); } }
static void Server(NetMQContext context) { using (var pub = context.CreatePublisherSocket()) { using (NetMQMonitor monitor = new NetMQMonitor(context, pub, "inproc://pub.inproc", SocketEvent.Accepted | SocketEvent.Listening | SocketEvent.Disconnected )) { // for publisher/subscriber mode, only the following events happen monitor.Accepted += new EventHandler
(monitor_Accepted); monitor.Listening += new EventHandler (monitor_Listening); monitor.Disconnected += new EventHandler (monitor_Disconnected); monitor.Timeout = TimeSpan.FromMilliseconds(100);
// be careful with the event handlers, if an exception is thrown, monitor will die! var pollerTask = Task.Factory.StartNew(monitor.Start);
// publisher uses 'bind' (subscriber uses 'connect') pub.Bind("tcp://*:5002"); pub.Options.DelayAttachOnConnect = false;
for (int i = 0; i < 1000; i++) { pub.Send("Hello" + i.ToString()); Thread.Sleep(25); } } } }
static void monitor_Disconnected(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Disconnected: " + e.Socket.RemoteEndPoint.ToString()); }
static void monitor_Listening(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Listening on: " + e.Socket.LocalEndPoint.ToString()); }
static void monitor_Accepted(object sender, NetMQMonitorSocketEventArgs e) { Console.WriteLine("Accepted: " + e.Socket.RemoteEndPoint.ToString()); } } }
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:55 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
Yes of course.
On Mon, Aug 26, 2013 at 3:33 PM, meraydin <notifications@github.com mailto:notifications@github.com%20%0b> mailto:notifications@github.com> wrote:
Hi Doron,
Thanks for the reply. I was trying to find my way on those samples ☹ I suppose I can use this with Publisher socket type too, am I right?
From: Doron Somech [mailto:notifications@github.com] Sent: Monday, August 26, 2013 3:28 PM To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
You can use the monitor directly or from Poller, anyway take a look at the tests:
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/MonitorPollTests.cs
https://github.com/zeromq/netmq/blob/master/src/NetMQ.Tests/PollerTests.cs
On Mon, Aug 26, 2013 at 2:45 PM, meraydin <notifications@github.com mailto:notifications@github.com%20%0b> mailto:notifications@github.com%20%0b> mailto:notifications@github.com> wrote:
I suppose this class is responsible for socket_connected, socket_disconnected, v.s. events. Is there any sample code about how to use this in a PUB/SUB model? (I'm looking for subscriber connected, disconnected events)
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23259052>.
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23259289> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23260390>.
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23261569> .
— Reply to this email directly or view it on GitHub< https://github.com/zeromq/netmq/issues/97#issuecomment-23284476>.
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-23293358 .
As @Somdoron already mentioned, the Socket class is not thread safe. That and the strong argument against locks in the Zmq Guide lead me to write this question on Stack Overflow , maybe the answers are can help you too @meraydin .
@meraydin can I close the issue?
Yes please. Thanks
From: Doron Somech [mailto:notifications@github.com] Sent: 12 Aralık 2013 Perşembe 22:41 To: zeromq/netmq Cc: Murat Eraydın Subject: Re: [netmq] NetMQMonitor sample (#97)
@meraydinhttps://github.com/meraydin can I close the issue?
— Reply to this email directly or view it on GitHubhttps://github.com/zeromq/netmq/issues/97#issuecomment-30459602.
I suppose this class is responsible for socket_connected, socket_disconnected, v.s. events. Is there any sample code about how to use this in a PUB/SUB model? (I'm looking for subscriber connected, disconnected events)