[nanomsg] Re: Messages get lost using the pub/sub model

  • From: 李捷 <lijielile@xxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Sun, 5 Jun 2016 14:50:38 -0400

Thanks for the reply. Spent a lot of time to debug this and tried to make
the server sleep for 1 second. Did't try to make it sleep for 2
seconds......

On Sun, Jun 5, 2016 at 2:48 PM, Garrett D'Amore <garrett@xxxxxxxxxx> wrote:

Put another way, when the PUB server “sends” it does not block — it sends
to all pipes that are *connected at that time*, and are not experiencing
flow control.  Any clients not connected won’t see messages that might have
been published earlier.

On Sun, Jun 5, 2016 at 11:47 AM, Garrett D'Amore <garrett@xxxxxxxxxx>
wrote:

The first message the server sends is lost, because the clients haven’t
connected yet when the send takes place.

If you ask the server to wait for > 1 sec (perhaps 2 seconds) before
sending the first message, then that will give the clients a chance to
connect, and it will be fine.

 - Garrett


On Sun, Jun 5, 2016 at 11:40 AM, 李捷 <lijielile@xxxxxxxxx> wrote:

I am planning to use the pub/sub model to broadcast messages from one
thread to multiple threads.  However, after playing around with it I found
when broadcasting messages from the server node to the client nodes, the
first messages can't be received. If I sent two messages from the server,
only the second one is received and if I send three, the last two got
received. If I only send one message, the receiving node block for ever
waiting for the messages. Did I miss anything? Also, by looking at the
sample from the tutorial, it is obvious that messages got lost too.  Below
is copied from the tutorial page. Obviously 6 messages were sent and only 4
were received?

gcc pubsub.c /usr/local/lib/libnanomsg.a -o pubsub./pubsub server 
ipc:///tmp/pubsub.ipc & server=$! && sleep 1./pubsub client 
ipc:///tmp/pubsub.ipc client0 & client0=$!./pubsub client 
ipc:///tmp/pubsub.ipc client1 & client1=$!./pubsub client 
ipc:///tmp/pubsub.ipc client2 & client2=$!sleep 5kill $server $client0 
$client1 $client2

SERVER: PUBLISHING DATE Sat Sep  7 17:40:11 2013
SERVER: PUBLISHING DATE Sat Sep  7 17:40:12 2013
SERVER: PUBLISHING DATE Sat Sep  7 17:40:13 2013
CLIENT (client2): RECEIVED Sat Sep  7 17:40:13 2013
CLIENT (client0): RECEIVED Sat Sep  7 17:40:13 2013
CLIENT (client1): RECEIVED Sat Sep  7 17:40:13 2013
SERVER: PUBLISHING DATE Sat Sep  7 17:40:14 2013
CLIENT (client2): RECEIVED Sat Sep  7 17:40:14 2013
CLIENT (client1): RECEIVED Sat Sep  7 17:40:14 2013
CLIENT (client0): RECEIVED Sat Sep  7 17:40:14 2013
SERVER: PUBLISHING DATE Sat Sep  7 17:40:15 2013
CLIENT (client1): RECEIVED Sat Sep  7 17:40:15 2013
CLIENT (client2): RECEIVED Sat Sep  7 17:40:15 2013
CLIENT (client0): RECEIVED Sat Sep  7 17:40:15 2013
SERVER: PUBLISHING DATE Sat Sep  7 17:40:16 2013
CLIENT (client1): RECEIVED Sat Sep  7 17:40:16 2013
CLIENT (client2): RECEIVED Sat Sep  7 17:40:16 2013
CLIENT (client0): RECEIVED Sat Sep  7 17:40:16 2013




Other related posts: