[zeromq-dev] NetMQ behavior question
Osiris Pedroso
opedroso at gmail.com
Wed Oct 4 13:04:43 CEST 2017
I got one of this example from
http://netmq.readthedocs.io/en/latest/transports/#tcp
'''
using (var end1 = new PairSocket())
using (var end2 = new PairSocket())
{
end1.Bind("inproc://inproc-demo");
end2.Connect("inproc://inproc-demo");
var end1Task = Task.Run(() =>
{
Console.WriteLine("ThreadId = {0}",
Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("Sending hello down the inproc pipeline");
end1.SendFrame("Hello");
});
var end2Task = Task.Run(() =>
{
Console.WriteLine("ThreadId = {0}",
Thread.CurrentThread.ManagedThreadId);
var message = end2.ReceiveFrameString();
Console.WriteLine(message);
});
Task.WaitAll(new[] { end1Task, end2Task });
}
'''
And separated it in two, changing from inproc to tcp:
Producer:
=========
'''
using NetMQ;
using NetMQ.Sockets;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace NetMQInprocProducer
{
class Program
{
static void Main(string[] args)
{
using (var end1 = new PairSocket())
{
end1.Bind("tcp://*:5555");
var end1Task = Task.Run(() =>
{
Console.WriteLine("ThreadId = {0}",
Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("Sending hello down the inproc
pipeline");
end1.SendFrame("Hello");
});
Task.WaitAll(new[] { end1Task });
}
Console.ReadLine();
}
}
}
'''
Consumer:
=========
'''
using NetMQ;
using NetMQ.Sockets;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace NetMQInprocConsumer
{
class Program
{
static void Main(string[] args)
{
using (var end2 = new PairSocket())
{
end2.Connect("tcp://localhost:5555");
var end2Task = Task.Run(() =>
{
Console.WriteLine("ThreadId = {0}",
Thread.CurrentThread.ManagedThreadId);
var message = end2.ReceiveFrameString();
Console.WriteLine(message);
});
Task.WaitAll(new[] { end2Task });
}
Console.ReadLine();
}
}
}
'''
It all runs fine. I can start either consumer or producer and they wait for
each other.
Notice that both end in a Console.ReadLine() statement, which holds the
process alive until I press ENTER on either console that has reached that
statement.
My question is why do both processes exit when I press ENTER in either of
them?
Same behavior is reproducible if I started multiple consumers and a single
producer.
When I run producer, one of the consumers gets the message, but now if I
press ENTER on the producer or the consumer that received the message, all
instances of both consumer and producer exit they processes.
One has exit code 0, the others with exit code -1.
The Visual Studio IDE does not indicate that any exceptions were thrown.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20171004/fbc24b23/attachment.htm>
More information about the zeromq-dev
mailing list