Source

kschiess.bitbucket.org / nanomsg / reqrep.html

Full commit
<!DOCTYPE html><html><head><title>nanomsg (Ruby)</title><meta content="width=device-width, initial-scale=1.0" name="viewport" /><link href="stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" /><link href="stylesheets/bootstrap-theme.min.css" media="screen" rel="stylesheet" type="text/css" /><link href="stylesheets/code.css" media="screen" rel="stylesheet" type="text/css" /><link href="stylesheets/nanomsg.css" media="screen" rel="stylesheet" type="text/css" /><script src="javascripts/bootstrap.min.js" type="text/javascript"></script></head><body><div class="container menu"><div class="row"><div class="col-md-2 menu-item"><a href="./">ABOUT</a></div></div><div class="row"><div class="col-md-2 menu-item"><a href="pair.html">PAIR</a></div><div class="col-md-2 menu-item active">REQ/REP</div><div class="col-md-2 menu-item"><a href="pubsub.html">PUB/SUB</a></div><div class="col-md-2 menu-item"><a href="surveyrespond.html">SURVEY/RESPOND</a></div><div class="col-md-2 menu-item"><a href="pushpull.html">PUSH/PULL</a></div><div class="col-md-2 menu-item"><a href="bus.html">BUS</a></div></div><div class="row"><div class="col-md-2 menu-item"><a href="documentation.html">DOCUMENTATION</a></div><div class="col-md-2 menu-item"><a href="contrib.html">CONTRIB</a></div></div></div><div class="container"><div class="row"><div class="schema"><img src="images/reqrep.png" /></div><div class="caption">Messages travel from a REQ node (client) 
to a REP node (service)
and back again.</div></div><div class="row text"><div class="col-md-6 sample"><pre class="highlight ruby"><span class="nb">require</span> <span class="s1">'nanomsg'</span>

<span class="n">req</span> <span class="o">=</span> <span class="no">NanoMsg</span><span class="o">::</span><span class="no">ReqSocket</span><span class="nf">.new</span>
<span class="n">req</span><span class="nf">.connect</span><span class="p">(</span><span class="s1">'tcp://127.0.0.1:4568'</span><span class="p">)</span>

<span class="n">req</span><span class="nf">.send</span> <span class="s1">'req 1'</span>
<span class="nb">p</span> <span class="n">req</span><span class="nf">.recv</span> <span class="c1"># =&gt; &quot;rep 1&quot;</span>
</pre></div><div class="col-md-6 sample"><pre class="highlight ruby"><span class="nb">require</span> <span class="s1">'nanomsg'</span>

<span class="n">rep</span> <span class="o">=</span> <span class="no">NanoMsg</span><span class="o">::</span><span class="no">RepSocket</span><span class="nf">.new</span>
<span class="n">rep</span><span class="nf">.bind</span><span class="p">(</span><span class="s1">'tcp://127.0.0.1:4568'</span><span class="p">)</span>

<span class="n">rep</span><span class="nf">.recv</span> <span class="c1"># =&gt; 'req 1'</span>
<span class="n">rep</span><span class="nf">.send</span> <span class="s1">'rep 1'</span>
</pre></div></div></div></body></html>