<html><head><metahttp-equiv="content-type"content="text/html; charset=utf-8"/><title>4 Drivers</title><linkrel="stylesheet"type="text/css"href="scribble.css"title="default"/><linkrel="stylesheet"type="text/css"href="racket.css"title="default"/><linkrel="stylesheet"type="text/css"href="scribble-style.css"title="default"/><scripttype="text/javascript"src="scribble-common.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><bodyid="scribble-racket-lang-org"><divclass="tocset"><divclass="tocview"><divclass="tocviewlist"style="margin-bottom: 1em;"><divclass="tocviewtitle"><tablecellspacing="0"cellpadding="0"><tr><tdstyle="width: 1em;"><ahref="javascript:void(0);"title="Expand/Collapse"class="tocviewtoggle"onclick="TocviewToggle(this,"tocview_0");">▼</a></td><td></td><td><ahref="index.html"class="tocviewlink"data-pltdoc="x">Marketplace:<spanclass="mywbr"> </span> Network-<wbr></wbr>Aware Programming</a></td></tr></table></div><divclass="tocviewsublisttop"style="display: block;"id="tocview_0"><tablecellspacing="0"cellpadding="0"><tr><tdalign="right">1 </td><td><ahref="Concepts.html"class="tocviewlink"data-pltdoc="x">Concepts</a></td></tr><tr><tdalign="right">2 </td><td><ahref="high-level-interface.html"class="tocviewlink"data-pltdoc="x">High-<wbr></wbr>level interface</a></td></tr><tr><tdalign="right">3 </td><td><ahref="low-level-interface.html"class="tocviewlink"data-pltdoc="x">Low-<wbr></wbr>level interface</a></td></tr><tr><tdalign="right">4 </td><td><ahref=""class="tocviewselflink"data-pltdoc="x">Drivers</a></td></tr><tr><tdalign="right">5 </td><td><ahref="Management_and_Monitoring.html"class="tocviewlink"data-pltdoc="x">Management and Monitoring</a></td></tr><tr><tdalign="right">6 </td><td><ahref="Examples.html"class="tocviewlink"data-pltdoc="x">Examples</a></td></tr></table></div></div><divclass="tocviewlist"><tablecellspacing="0"cellpadding="0"><tr><tdstyle="width: 1em;"><ahref="javascript:void(0);"title="Expand/Collapse"class="tocviewtoggle"onclick="TocviewToggle(this,"tocview_1");">►</a></td><td>4 </td><td><ahref=""class="tocviewselflink"data-pltdoc="x">Drivers</a></td></tr></table><divclass="tocviewsublistbottom"style="display: none;"id="tocview_1"><tablecellspacing="0"cellpadding="0"><tr><tdalign="right">4.1 </td><td><ahref="#%28part._event-relay%29"class="tocviewlink"data-pltdoc="x">event-<wbr></wbr>relay</a></td></tr><tr><tdalign="right">4.2 </td><td><ahref="#%28part._tcp-bare%29"class="tocviewlink"data-pltdoc="x">tcp-<wbr></wbr>bare</a></td></tr><tr><tdalign="right">4.3 </td><td><ahref="#%28part._timer__typed_and_untyped_%29"class="tocviewlink"data-pltdoc="x">timer (typed and untyped)</a></td></tr><tr><tdalign="right">4.4 </td><td><ahref="#%28part._udp__typed_and_untyped_%29"class="tocviewlink"data-pltdoc="x">udp (typed and untyped)</a></td></tr></table></div></div></div><divclass="tocsub"><divclass="tocsubtitle">On this page:</div><tableclass="tocsublist"cellspacing="0"><tr><td><spanclass="tocsublinknumber">4.1<tt> </tt></span><ahref="#%28part._event-relay%29"class="tocsubseclink"data-pltdoc="x">event-<wbr></wbr>relay</a></td></tr><tr><td><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Fevent-relay..rkt%29._event-relay%29%29"class="tocsubnonseclink"data-pltdoc="x"><spantitle="Provided from: marketplace/drivers/event-relay"><spanclass="RktSym"><spanclass="RktValLink">event-<wbr></wbr>relay</span></span></span></a></td></tr><tr><td><spanclass="tocsublinknumber">4.2<tt> </tt></span><ahref="#%28part._tcp-bare%29"class="tocsubseclink"data-pltdoc="x">tcp-<wbr></wbr>bare</a></td></tr><tr><td><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-driver%29%29"class="tocsubnonseclink"data-pltdoc="x"><spantitle="Provided from: marketplace/drivers/tcp-bare"><spanclass="RktSym"><spanclass="RktValLink">tcp-<wbr></wbr>driv
world using <spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._ground-vm%29%29"class="RktStxLink"data-pltdoc="x">ground-vm</a></span>-level event-based subscriptions.</div></p></div><divclass="SIntrapara">Returns a <spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._spawn%29%29"class="RktStxLink"data-pltdoc="x">spawn</a></span> which starts an event-relay process with
debug-name <spanclass="RktVal">`</span><spanclass="RktVal">(</span><spanclass="RktVal">event-relay</span><spanclass="stt"></span><spanclass="RktRdr">,</span><spanclass="RktVar">self-id</span><spanclass="RktVal">)</span>.</div><divclass="SIntrapara">The relay process observes subscriptions matching the topic-pattern
<spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29"class="RktValLink"data-pltdoc="x">cons</a></span><spanclass="stt"></span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="low-level-interface.html#%28def._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._~3f%29%29"class="RktValLink"data-pltdoc="x">?</a></span><spanclass="stt"></span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/sync.html#%28def._%28%28quote._~23~25kernel%29._evt~3f%29%29"class="RktValLink"data-pltdoc="x">evt?</a></span><spanclass="RktPn">)</span><spanclass="stt"></span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29.__%29%29"class="RktStxLink"data-pltdoc="x">_</a></span><spanclass="RktPn">)</span>, and when one appears, constructs an
analogous one using <spanclass="RktSym"><ahref="high-level-interface.html#%28def._%28%28lib._marketplace%2Fsugar-values..rkt%29._at-meta-level%29%29"class="RktValLink"data-pltdoc="x">at-meta-level</a></span> to connect to the next VM
down the stack. Messages from the meta-level will be relayed up to the
current level. When the subscription disappears, the relay withdraws
the subscription at the meta-level as well.</div></p><h4>4.2<tt> </tt><aname="(part._tcp-bare)"></a><aname="(mod-path._marketplace/drivers/tcp-bare)"></a>tcp-bare</h4><p><divclass="SIntrapara"><tablecellspacing="0"class="defmodule"><tr><td><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29"class="RktStxLink"data-pltdoc="x">require</a></span><spanclass="stt"></span><ahref="#%28mod-path._marketplace%2Fdrivers%2Ftcp-bare%29"class="RktModLink"data-pltdoc="x"><spanclass="RktSym">marketplace/drivers/tcp-bare</span></a><spanclass="RktPn">)</span></td></tr></table></div><divclass="SIntrapara">This module is only available for use by untyped Racket processes. It
is included by default in programs using <spanclass="stt">#lang marketplace</span>; see
<ahref="high-level-interface.html#%28part._hashlang-variations%29"data-pltdoc="x">Using <spanclass="stt">#lang marketplace</span> and friends</a> for information on other language
variants.</div><divclass="SIntrapara"><p><divclass="SIntrapara"><blockquoteclass="SVInsetFlow"><tablecellspacing="0"class="boxed RBoxed"><tr><td><blockquoteclass="SubFlow"><divclass="RBackgroundLabel SIEHidden"><divclass="RBackgroundLabelInner"><p>procedure</p></div></div><pclass="RForeground"><spanclass="RktPn">(</span><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-driver))"></a><spantitle="Provided from: marketplace/drivers/tcp-bare"><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-driver%29%29"class="RktValLink"data-pltdoc="x">tcp-driver</a></span></span><spanclass="RktPn"></span><spanclass="RktPn">)</span><spanclass="hspace"> </span>→<spanclass="hspace"> </span><spanclass="RktSym"><ahref="low-level-interface.html#%28def._%28%28lib._marketplace%2Fmain..rkt%29._.Spawn%29%29"class="RktValLink"data-pltdoc="x">Spawn</a></span></p></blockquote></td></tr></table></blockquote></div><divclass="SIntrapara">Returns a <spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._spawn%29%29"class="RktStxLink"data-pltdoc="x">spawn</a></span> action which starts a TCP driver. The TCP
with a running <spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Fevent-relay..rkt%29._event-relay%29%29"class="RktValLink"data-pltdoc="x">event-relay</a></span>.</div></p></div><divclass="SIntrapara"><p><divclass="SIntrapara"><blockquoteclass="SVInsetFlow"><tablecellspacing="0"class="boxed RBoxed"><tr><td><blockquoteclass="SubFlow"><divclass="RBackgroundLabel SIEHidden"><divclass="RBackgroundLabelInner"><p>value</p></div></div><pclass="RForeground"><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp))"></a><spantitle="Provided from: marketplace/drivers/tcp-bare"><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp%29%29"class="RktValLink"data-pltdoc="x">tcp</a></span></span><spanclass="hspace"> </span>:<spanclass="hspace"> </span><spanclass="RktSym"><ahref="low-level-interface.html#%28def._%28%28lib._marketplace%2Fmain..rkt%29._.Spawn%29%29"class="RktValLink"data-pltdoc="x">Spawn</a></span></p></blockquote></td></tr></table></blockquote></div><divclass="SIntrapara">A pre-made <spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._spawn%29%29"class="RktStxLink"data-pltdoc="x">spawn</a></span> action equivalent to <spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-driver%29%29"class="RktValLink"data-pltdoc="x">tcp-driver</a></span><spanclass="RktPn">)</span>.</div></p></div></p><h5>4.2.1<tt> </tt><aname="(part._.T.C.P_channels)"></a>TCP channels</h5><p><divclass="SIntrapara"><blockquoteclass="SVInsetFlow"><tablecellspacing="0"class="boxed RBoxed"><tr><td><blockquoteclass="SubFlow"><divclass="RBackgroundLabel SIEHidden"><divclass="RBackgroundLabelInner"><p>struct</p></div></div><tablecellspacing="0"class="RForeground"><tr><td><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29"class="RktStxLink"data-pltdoc="x">struct</a></span></td><td><spanclass="hspace"> </span></td><td><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-channel-subpacket))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-channel-destination))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-channel-source))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-channel~3f))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._struct~3atcp-channel))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-channel))"></a><spantitle="Provided from: marketplace/drivers/tcp-bare"><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-channel%29%29"class="RktValLink"data-pltdoc="x">tcp-channel</a></span></span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">source</span><spanclass="stt"></span><spanclass="RktSym">destination</span><spanclass="stt"></span><spanclass="RktSym">subpacket</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span></td><td><spanclass="hspace"> </span></td><td><spanclass="RktPn">#:prefab</span><spanclass="RktPn">)</span></td></tr></table></blockquote></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktSym">source</span><spanclass="hspace"> </span>:<spanclass="hspace"> </span><spanclass="RktSym">TcpAddress</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktSym">destination</span><spanclass="hspace"> </span>:<spanclass="hspace"> </span><spanclass="RktSym">TcpAddress</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktSym">subpacket</span><spanclass="hspace"> </span>:<spanclass="hspace"> </span><spanclass="RktSym">TcpSubPacket</span></td></tr></table></blockquote></div><divclass="SIntrapara">A TCP channel represents a section of a unidi
(local-to-remote) bytestream.</div></p><p><divclass="SIntrapara"><blockquoteclass="SVInsetFlow"><tablecellspacing="0"class="boxed RBoxed"><tr><td><blockquoteclass="SubFlow"><divclass="RBackgroundLabel SIEHidden"><divclass="RBackgroundLabelInner"><p>type</p></div></div><pclass="RForeground"><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._.Tcp.Sub.Packet))"></a><spantitle="Provided from: marketplace/drivers/tcp-bare"><spanclass="RktSym">TcpSubPacket</span></span><spanclass="hspace"> </span>:<spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">or/c</span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/port-ops.html#%28def._%28%28quote._~23~25kernel%29._eof-object~3f%29%29"class="RktValLink"data-pltdoc="x">eof-object?</a></span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes~3f%29%29"class="RktValLink"data-pltdoc="x">bytes?</a></span><spanclass="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><divclass="SIntrapara">Packets carried by <spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-channel%29%29"class="RktValLink"data-pltdoc="x">tcp-channel</a></span> structures are either
vectors.</div></p><h5>4.2.2<tt> </tt><aname="(part._.T.C.P_addresses)"></a>TCP addresses</h5><p><divclass="SIntrapara"><blockquoteclass="SVInsetFlow"><tablecellspacing="0"class="boxed RBoxed"><tr><td><blockquoteclass="SubFlow"><divclass="RBackgroundLabel SIEHidden"><divclass="RBackgroundLabelInner"><p>type</p></div></div><pclass="RForeground"><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._.Tcp.Address))"></a><spantitle="Provided from: marketplace/drivers/tcp-bare"><spanclass="RktSym">TcpAddress</span></span><spanclass="hspace"> </span>:<spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">or/c</span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-address~3f%29%29"class="RktValLink"data-pltdoc="x">tcp-address?</a></span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-handle~3f%29%29"class="RktValLink"data-pltdoc="x">tcp-handle?</a></span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-listener~3f%29%29"class="RktValLink"data-pltdoc="x">tcp-listener?</a></span><spanclass="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><divclass="SIntrapara">A TCP address describes one end of a TCP connection. It can be either</div></p><ul><li><p>a <spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-address%29%29"class="RktValLink"data-pltdoc="x">tcp-address</a></span>, representing a remote socket;</p></li><li><p>a <spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-handle%29%29"class="RktValLink"data-pltdoc="x">tcp-handle</a></span>, representing a local socket on a kernel-assigned port; or</p></li><li><p>a <spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-listener%29%29"class="RktValLink"data-pltdoc="x">tcp-listener</a></span>, representing a local socket on a user-assigned port.</p></li></ul><p><divclass="SIntrapara"><blockquoteclass="SVInsetFlow"><tablecellspacing="0"class="boxed RBoxed"><tr><td><blockquoteclass="SubFlow"><divclass="RBackgroundLabel SIEHidden"><divclass="RBackgroundLabelInner"><p>struct</p></div></div><tablecellspacing="0"class="RForeground"><tr><td><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29"class="RktStxLink"data-pltdoc="x">struct</a></span></td><td><spanclass="hspace"> </span></td><td><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-address-port))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-address-host))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-address~3f))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._struct~3atcp-address))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-address))"></a><spantitle="Provided from: marketplace/drivers/tcp-bare"><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-address%29%29"class="RktValLink"data-pltdoc="x">tcp-address</a></span></span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">host</span><spanclass="stt"></span><spanclass="RktSym">port</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span></td><td><spanclass="hspace"> </span></td><td><spanclass="RktPn">#:prefab</span><spanclass="RktPn">)</span></td></tr></table></blockquote></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktSym">host</span><spanclass="hspace"> </span>:<spanclass="hspace"> </span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/strings.html#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29"class="RktValLink"data
ASCII representation of an IP address (e.g. <spanclass="RktVal">"127.0.0.1"</span>).</div></p><p><divclass="SIntrapara"><blockquoteclass="SVInsetFlow"><tablecellspacing="0"class="boxed RBoxed"><tr><td><blockquoteclass="SubFlow"><divclass="RBackgroundLabel SIEHidden"><divclass="RBackgroundLabelInner"><p>struct</p></div></div><tablecellspacing="0"class="RForeground"><tr><td><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29"class="RktStxLink"data-pltdoc="x">struct</a></span></td><td><spanclass="hspace"> </span></td><td><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-handle-id))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-handle~3f))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._struct~3atcp-handle))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-handle))"></a><spantitle="Provided from: marketplace/drivers/tcp-bare"><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-handle%29%29"class="RktValLink"data-pltdoc="x">tcp-handle</a></span></span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">id</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span></td><td><spanclass="hspace"> </span></td><td><spanclass="RktPn">#:prefab</span><spanclass="RktPn">)</span></td></tr></table></blockquote></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktSym">id</span><spanclass="hspace"> </span>:<spanclass="hspace"> </span><spanclass="RktSym">any/c</span></td></tr></table></blockquote></div><divclass="SIntrapara">Describes a local half-connection with a kernel-assigned port number.
The port number is not directly accessible; the <spanclass="RktSym">id</span> is used as
a local name for whichever underlying port number ends up being used.</div></p><p>The <spanclass="RktSym">id</span> must be chosen carefully: it is scoped to the local
VM, i.e. shared between processes in that VM, so processes must make
sure not to accidentally clash in handle ID selection. They are also
used in TcpChannel to mean a specific <spanstyle="font-style: italic">instance</span> of a TCP
connection, so if you are likely to want to reconnect individual
flows, use different values for <spanclass="RktSym">id</span>.</p><p><divclass="SIntrapara"><blockquoteclass="SVInsetFlow"><tablecellspacing="0"class="boxed RBoxed"><tr><td><blockquoteclass="SubFlow"><divclass="RBackgroundLabel SIEHidden"><divclass="RBackgroundLabelInner"><p>struct</p></div></div><tablecellspacing="0"class="RForeground"><tr><td><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29"class="RktStxLink"data-pltdoc="x">struct</a></span></td><td><spanclass="hspace"> </span></td><td><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-listener-port))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-listener~3f))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._struct~3atcp-listener))"></a><aname="(def._((lib._marketplace/drivers/tcp-bare..rkt)._tcp-listener))"></a><spantitle="Provided from: marketplace/drivers/tcp-bare"><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-listener%29%29"class="RktValLink"data-pltdoc="x">tcp-listener</a></span></span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">port</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span></td><td><spanclass="hspace"> </span></td><td><spanclass="RktPn">#:prefab</span><spanclass="RktPn">)</span></td></tr></table></blockquote></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktSym">port</span><spanclass="hspace"> </span>:<spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">integer-in</span><spanclass="hspace"> </span><spanclass="RktVal">0</span><spanclass="hspace"> </span><spanclass="RktVal">65535</span><spanclass="RktPn">)</span></td></tr></table></blockquote></div><divclass="SIntrapara">Describes a local half-connection with a user-assigned port number.
Use this to describe server sockets.</div></p><h5>4.2.3<tt> </tt><aname="(part._.Opening_an_outbound_connection)"></a>Opening an outbound connection</h5><p>Choose a <spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-handle%29%29"class="RktValLink"data-pltdoc="x">tcp-handle</a></span>, and then create endpoints as follows:</p><blockquoteclass="SCodeFlow"><tablecellspacing="0"class="RktBlk"><tr><td><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/let.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let%29%29"class="RktStxLink"data-pltdoc="x">let</a></span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktPn">(</span><spanclass="RktSym">local</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-handle%29%29"class="RktValLink"data-pltdoc="x">tcp-handle</a></span><spanclass="hspace"> </span><spanclass="RktVal">'</span><spanclass="RktVal">some-unique-value</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">remote</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-address%29%29"class="RktValLink"data-pltdoc="x">tcp-address</a></span><spanclass="hspace"> </span><spanclass="RktVal">"the.remote.host.example.com"</span><spanclass="hspace"> </span><spanclass="RktVal">5999</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-typed..rkt%29._transition%2Fno-state%29%29"class="RktStxLink"data-pltdoc="x">transition/no-state</a></span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._endpoint%29%29"class="RktStxLink"data-pltdoc="x">endpoint</a></span><spanclass="hspace"> </span><spanclass="RktPn">#:publisher</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-channel%29%29"class="RktValLink"data-pltdoc="x">tcp-channel</a></span><spanclass="hspace"> </span><spanclass="RktSym">local</span><spanclass="hspace"> </span><spanclass="RktSym">remote</span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="low-level-interface.html#%28def._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._~3f%29%29"class="RktValLink"data-pltdoc="x">?</a></span><spanclass="RktPn">)</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._endpoint%29%29"class="RktStxLink"data-pltdoc="x">endpoint</a></span><spanclass="hspace"> </span><spanclass="RktPn">#:subscriber</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-channel%29%29"class="RktValLink"data-pltdoc="x">tcp-channel</a></span><spanclass="hspace"> </span><spanclass="RktSym">remote</span><spanclass="hspace"> </span><spanclass="RktSym">local</span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="low-level-interface.html#%28def._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._~3f%29%29"class="RktValLink"data-pltdoc="x">?</a></span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> &
response to the presence of the endpoints. When the endpoints are
deleted (or the process exits), the TCP driver will notice the absence
and will close the underlying TCP socket.</p><p>For a complete example, see <ahref="Examples.html#%28part._chat-client-example%29"data-pltdoc="x">TCP chat client</a>.</p><h5>4.2.4<tt> </tt><aname="(part._.Accepting_inbound_connections)"></a>Accepting inbound connections</h5><p>Choose a port number, and then create an <spanstyle="font-style: italic">observer</span> endpoint as
follows:</p><blockquoteclass="SCodeFlow"><tablecellspacing="0"class="RktBlk"><tr><td><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._endpoint%29%29"class="RktStxLink"data-pltdoc="x">endpoint</a></span><spanclass="hspace"> </span><spanclass="RktPn">#:subscriber</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-channel%29%29"class="RktValLink"data-pltdoc="x">tcp-channel</a></span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="low-level-interface.html#%28def._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._~3f%29%29"class="RktValLink"data-pltdoc="x">?</a></span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-listener%29%29"class="RktValLink"data-pltdoc="x">tcp-listener</a></span><spanclass="hspace"> </span><spanclass="RktVal">5999</span><spanclass="RktPn">)</span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="low-level-interface.html#%28def._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._~3f%29%29"class="RktValLink"data-pltdoc="x">?</a></span><spanclass="RktPn">)</span><spanclass="hspace"> </span><spanclass="RktPn">#:observer</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">#:conversation</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-channel%29%29"class="RktValLink"data-pltdoc="x">tcp-channel</a></span><spanclass="hspace"> </span><spanclass="RktSym">them</span><spanclass="hspace"> </span><spanclass="RktSym">us</span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29.__%29%29"class="RktStxLink"data-pltdoc="x">_</a></span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">#:on-presence</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._spawn%29%29"class="RktStxLink"data-pltdoc="x">spawn</a></span><spanclass="hspace"> </span><spanclass="RktPn">#:child</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">chat-session</span><spanclass="hspace"> </span><spanclass="RktSym">them</span><spanclass="hspace"> </span><spanclass="RktSym">us</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span></td></tr></table></blockquote><p>The use of <spanclass="RktPn">#:observer</span> here indicates that this endpoint isn’t
communicating on the newly-arrived socket.</p><p>To illustrate the code for handling a newly-arrived connection,</p><blockquoteclass="SCodeFlow"><tablecellspacing="0"class="RktBlk"><tr><td><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/ts-reference/special-forms.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._define%29%29"class="RktStxLink"data-pltdoc="x">define</a></span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">chat-session</span><spanclass="hspace"> </span><spanclass="RktSym">them</span><spanclass="hspace"> </span><spanclass="RktSym">us</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-typed..rkt%29._transition%2Fno-state%29%29"class="RktStxLink"data-pltdoc="x">transition/no-state</a></span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="high-level-interface.html#%28form._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._endpoint%29%29"class="RktStxLink"data-pltdoc="x">endpoint</a></span><spanclass="hspace"> </span><spanclass="RktPn">#:subscriber</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-channel%29%29"class="RktValLink"data-pltdoc="x">tcp-channel</a></span><spanclass="hspace"> </span><spanclass="RktSym">them</span><spanclass="hspace"> </span><spanclass="RktSym">us</span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="low-level-interface.html#%28def._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._~3f%29%29"class="RktValLink"data-pltdoc="x">?</a></span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">#:on-absence</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="high-level-interface.html#%28def._%28%28lib._marketplace%2Fsugar-values..rkt%29._quit%29%29"class="RktValLink"data-pltdoc="x">quit</a></span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">[</span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-channel%29%29"class="RktValLink"data-pltdoc="x">tcp-channel</a></span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29.__%29%29"class="RktStxLink"data-pltdoc="x">_</a></span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29.__%29%29"class="RktStxLink"data-pltdoc="x">_</a></span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="low-level-interface.html#%28def._%28%28lib._marketplace%2Fsugar-untyped..rkt%29._~3f%29%29"class="RktValLink"data-pltdoc="x">?</a></span><spanclass="hspace"> </span><spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes~3f%29%29"class="RktValLink"data-pltdoc="x">bytes?</a></span><spanclass="hspace"> </span><spanclass="RktSym">data</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktCmt">;</span><spanclass="RktCmt"> </span><spanclass="RktCmt">Handle incoming data</span></td></tr><tr><td><spanclass="hspace"> &nbs
<spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes~3f%29%29"class="RktValLink"data-pltdoc="x">bytes?</a></span>.</p><h5>4.2.6<tt> </tt><aname="(part._.Sending_data)"></a>Sending data</h5><p>Send data with</p><blockquoteclass="SCodeFlow"><p><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="high-level-interface.html#%28def._%28%28lib._marketplace%2Fsugar-values..rkt%29._send-message%29%29"class="RktValLink"data-pltdoc="x">send-message</a></span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym"><ahref="#%28def._%28%28lib._marketplace%2Fdrivers%2Ftcp-bare..rkt%29._tcp-channel%29%29"class="RktValLink"data-pltdoc="x">tcp-channel</a></span><spanclass="hspace"> </span><spanclass="RktSym">local-address</span><spanclass="hspace"> </span><spanclass="RktSym">remote-address</span><spanclass="hspace"> </span><spanclass="RktSym">subpacket</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span></p></blockquote><p>where, as for receiving data, the <spanclass="RktSym">subpacket</span> is either
<spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/port-ops.html#%28def._%28%28quote._~23~25kernel%29._eof%29%29"class="RktValLink"data-pltdoc="x">eof</a></span> or a <spanclass="RktSym"><ahref="http://docs.racket-lang.org/reference/bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes~3f%29%29"class="RktValLink"data-pltdoc="x">bytes?</a></span>.</p><h4>4.3<tt> </tt><aname="(part._timer__typed_and_untyped_)"></a>timer (typed and untyped)</h4><p>For examples of the use of the timer driver, see uses of
<spanclass="RktSym">set-timer</span> and <spanclass="RktSym">timer-expired</span> in
Marketplace-based DNS resolver</a>.</p><h4>4.4<tt> </tt><aname="(part._udp__typed_and_untyped_)"></a>udp (typed and untyped)</h4><p>For examples of the use of the UDP driver, see uses of
Marketplace-based DNS resolver</a>.</p><divclass="navsetbottom"><spanclass="navleft"> </span><spanclass="navright"> <ahref="low-level-interface.html"title="backward to "3 Low-level interface""data-pltdoc="x">← prev</a> <ahref="index.html"title="up to "Marketplace: Network-Aware Programming""data-pltdoc="x">up</a> <ahref="Management_and_Monitoring.html"title="forward to "5 Management and Monitoring""data-pltdoc="x">next →</a></span> </div></div></div><divid="contextindicator"> </div></body></html>