blob: b96a5dbfe4c9a52fed9bc3ef1e01b37d35eab8b1 [file] [log] [blame]
---
layout: default
---
:source-highlighter: coderay
:icons: font
include::banner.adoc[]
== Pair (Two Way Radio)
image::pair.png[Two Way Radio]
The pair pattern is used when there a one-to-one peer relationship.
Only one peer may be connected to another peer at a time, but both
may speak freely.
.pair.c
[source,c]
----
include::src/pair.c[]
----
<1> Blithely assumes message is ASCIIZ string. Real code should check it.
.Compilation
[source,bash]
----
gcc pair.c -lnanomsg -o pair
----
.Execution
[source,bash]
----
./pair node0 ipc:///tmp/pair.ipc & node0=$!
./pair node1 ipc:///tmp/pair.ipc & node1=$!
sleep 3
kill $node0 $node1
----
.Output
----
NODE1: SENDING DATE REQUEST DATE
NODE0: RECEIVED DATE REQUEST
NODE0: SENDING DATE Sat Sep 7 17:39:01 2013
NODE1: RECEIVED DATE Sat Sep 7 17:39:01 2013
----