world using <spanclass="RktSym">ground-vm</span>-level event-based subscriptions.</div></p></div><divclass="SIntrapara">Returns a <spanclass="RktSym">spawn</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">?</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">at-meta-level</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">tcp-driver</span></span><spanclass="RktPn"></span><spanclass="RktPn">)</span><spanclass="hspace"> </span>→<spanclass="hspace"> </span><spanclass="RktSym">Spawn</span></p></blockquote></td></tr></table></blockquote></div><divclass="SIntrapara">Returns a <spanclass="RktSym">spawn</span> action which starts a TCP driver. The TCP
driver should run either directly in a ground VM, or in a nested VM
with a running <spanclass="RktSym">event-relay</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">tcp-channel</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 unidirectional TCP flow
appearing on our local "subnet" of the full TCP network, complete with
source, destination and subpacket. Each TCP connection has two such
flows: one inbound (remote-to-local) bytestream, and one outbound
(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">tcp-channel</span> structures are either
end-of-file objects or raw binary data represented as Racket byte
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">tcp-address?</span><spanclass="hspace"> </span><spanclass="RktSym">tcp-handle?</span><spanclass="hspace"> </span><spanclass="RktSym">tcp-listener?</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">tcp-address</span>, representing a remote socket;</p></li><li><p>a <spanclass="RktSym">tcp-handle</span>, representing a local socket on a kernel-assigned port; or</p></li><li><p>a <spanclass="RktSym">tcp-listener</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">tcp-address</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-pltdoc="x">string?</a></span></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 remote half-connection. The <spanclass="RktSym">host</span> part is to be a
string containing either a hostname (e.g. <spanclass="RktVal">"localhost"</span>) or an
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">tcp-handle</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">tcp-listener</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">tcp-handle</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">tcp-handle</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">tcp-address</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">transition/no-state</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">endpoint</span><spanclass="hspace"> </span><spanclass="RktPn">#:publisher</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">tcp-channel</span><spanclass="hspace"> </span><spanclass="RktSym">local</span><spanclass="hspace"> </span><spanclass="RktSym">remote</span><spanclass="hspace"> </span><spanclass="RktSym">?</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">endpoint</span><spanclass="hspace"> </span><spanclass="RktPn">#:subscriber</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">tcp-channel</span><spanclass="hspace"> </span><spanclass="RktSym">remote</span><spanclass="hspace"> </span><spanclass="RktSym">local</span><spanclass="hspace"> </span><spanclass="RktSym">?</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">[</span><spanclass="RktPn">(</span><spanclass="RktSym">tcp-channel</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">?</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="RktPn">)</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktCmt">;</span><spanclass="RktCmt"> </span><spanclass="RktCmt">Handle a received end-of-file object</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">endpoint</span><spanclass="hspace"> </span><spanclass="RktPn">#:subscriber</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">tcp-channel</span><spanclass="hspace"> </span><spanclass="RktSym">?</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">tcp-listener</span><spanclass="hspace"> </span><spanclass="RktVal">5999</span><spanclass="RktPn">)</span><spanclass="hspace"> </span><spanclass="RktSym">?</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">tcp-channel</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">spawn</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
actually interested in exchanging any TCP data; instead, it is
monitoring demand for such exchanges. The TCP driver uses a rare
<spanclass="RktPn">#:everything</span> endpoint to monitor the presence of
<spanclass="RktPn">#:observer</span>s, and creates listening TCP server sockets in
response. When a connection comes in, the TCP driver spawns a manager
process which offers regular <spanclass="RktPn">#:participant</span> endpoints for
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">transition/no-state</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">endpoint</span><spanclass="hspace"> </span><spanclass="RktPn">#:subscriber</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">tcp-channel</span><spanclass="hspace"> </span><spanclass="RktSym">them</span><spanclass="hspace"> </span><spanclass="RktSym">us</span><spanclass="hspace"> </span><spanclass="RktSym">?</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">#:on-absence</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">quit</span><spanclass="RktPn">)</span></td></tr><tr><td><spanclass="hspace"> </span><spanclass="RktPn">[</span><spanclass="RktPn">(</span><spanclass="RktSym">tcp-channel</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">?</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"> </span><spanclass="RktPn">(</span><spanclass="RktSym">transition</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><spanclass="RktPn">]</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span><spanclass="RktPn">)</span></td></tr></table></blockquote><h5>4.2.5<tt> </tt><aname="(part._.Receiving_data)"></a>Receiving data</h5><p>TCP-related messages will be of the form</p><blockquoteclass="SCodeFlow"><p><spanclass="RktPn">(</span><spanclass="RktSym">tcp-channel</span><spanclass="hspace"> </span><spanclass="RktSym">remote-address</span><spanclass="hspace"> </span><spanclass="RktSym">local-address</span><spanclass="hspace"> </span><spanclass="RktSym">subpacket</span><spanclass="RktPn
<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">send-message</span><spanclass="hspace"> </span><spanclass="RktPn">(</span><spanclass="RktSym">tcp-channel</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>