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