📄 node495.html
字号:
<html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><!--Converted with jLaTeX2HTML 2002 (1.62) JA patch-1.4patched version by: Kenshi Muto, Debian Project.LaTeX2HTML 2002 (1.62),original version by: Nikos Drakos, CBLU, University of Leeds* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --><HTML><HEAD><TITLE>36.1.4 Transmitting user data over TCP</TITLE><META NAME="description" CONTENT="36.1.4 Transmitting user data over TCP"><META NAME="keywords" CONTENT="everything"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"><META NAME="Generator" CONTENT="jLaTeX2HTML v2002 JA patch-1.4"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><LINK REL="STYLESHEET" HREF="everything.css" tppabs="http://www.isi.edu/nsnam/ns/doc/everything.css"><LINK REL="next" HREF="node496.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node496.html"><LINK REL="previous" HREF="node494.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node494.html"><LINK REL="up" HREF="node491.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node491.html"><LINK REL="next" HREF="node496.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node496.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html9034" HREF="node496.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node496.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html9028" HREF="node491.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node491.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html9022" HREF="node494.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node494.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html9030" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html9032" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html9035" HREF="node496.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node496.html">36.1.5 Class hierarchy related</A><B> Up:</B> <A NAME="tex2html9029" HREF="node491.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node491.html">36.1 Using application-level data</A><B> Previous:</B> <A NAME="tex2html9023" HREF="node494.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node494.html">36.1.3 Transmitting user data</A>   <B> <A NAME="tex2html9031" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html9033" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <BR><BR><!--End of Navigation Panel--><H2><A NAME="SECTION07214000000000000000"></A><A NAME="sec:webcache-tcpapp"></A><BR>36.1.4 Transmitting user data over TCP</H2><P>Transmitting user data using TCP is trickier than doing that over UDP,mainly because of TCP's reassembly queue is only available forFullTcp. We deal with this problem by abstracting a TCP connection asa FIFO pipe. <P>As indicated in section <A HREF="node477.html#sec:upcalls" tppabs="http://www.isi.edu/nsnam/ns/doc/node477.html#sec:upcalls">35.2.4</A>, transmission of application datacan be implemented via agent upcalls. Assuming we are using TCP agents, all data are delivered in sequence, which means we can view the TCP connection as a FIFO pipe. We emulate user data transmission over TCPas follows. We first provide buffer for application data at the sender. Then we count the bytes received at the receiver. When the receiver has got all bytes of the current data transmission,it then gets the data directly from the sender. Class Application/TcpApp is used to implement this functionality.<P>A TcpApp object contains a pointer to a transport agent, presumably eithera FullTcp or a SimpleTcp.<A NAME="tex2html65" HREF="footnode.html#foot16577" tppabs="http://www.isi.edu/nsnam/ns/doc/footnode.html#foot16577"><SUP>36.1</SUP></A>(Currently TcpApp doesn't support asymmetric TCP agents, i.e., sender isseparated from receiver). It provides the following OTcl interfaces:<P><UL><LI><TT>connect</TT>: Connecting another TcpApp to this one. This connection is bi-directional, i.e., only one call to <TT>connect</TT> is needed, and data can be sent in either direction. </LI><LI><TT>send</TT>: It takes two arguments: <TT>(nbytes, str)</TT>. <TT>nbytes</TT> is the ``nominal'' size of application data. <TT>str</TT> is application data in string form.</LI></UL><P>In order to send application data in binary form, TcpApp provides a virtual C++ method <TT>send(int nbytes, int dsize, const char *data)</TT>.In fact, this is the method used to implement the OTcl method <TT>send</TT>.Because it's difficult to deal with binary data in Tcl, no OTcl interfaceis provided to handle binary data. <TT>nbytes</TT> is the number of bytes to be transmitted, <TT>dsize</TT> is the actual size of the array <TT>data</TT>.<P>TcpApp provides a C++ virtual method <TT>process_data(int size, char*data)</TT>to handle the received data. The default handling is to treat the data as a tcl script and evaluate the script. But it's easy to derive a classto provide other types of handling.<P>Here is an example of using Application/TcpApp. A similar example is <TT>Test/TcpApp-2node</TT> in /tcl/test/test-suite-webcache.tcl.First, we create FullTcp agents and connect them:<P><PRE> set tcp1 [new Agent/TCP/FullTcp] set tcp2 [new Agent/TCP/FullTcp] # Set TCP parameters here, e.g., window_, iss_, \ldots $ns attach-agent $n1 $tcp1 $ns attach-agent $n2 $tcp2 $ns connect $tcp1 $tcp2 $tcp2 listen</PRE><P>Then we create TcpApps and connect them:<P><PRE> set app1 [new Application/TcpApp $tcp1] set app2 [new Application/TcpApp $tcp2] $app1 connect $app2</PRE><P>Now we let <TT>$app1</TT> be sender and <TT>$app2</TT> be receiver:<P><PRE> $ns at 1.0 "$app1 send 100 \bs"$app2 app-recv 100\bs""</PRE> <P>Where <TT>app-recv</TT> is defined as:<P><PRE> Application/TcpApp instproc app-recv { size } { global ns puts "[$ns now] app2 receives data $size from app1" }</PRE><P><HR><!--Navigation Panel--><A NAME="tex2html9034" HREF="node496.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node496.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html9028" HREF="node491.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node491.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html9022" HREF="node494.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node494.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html9030" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html9032" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html9035" HREF="node496.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node496.html">36.1.5 Class hierarchy related</A><B> Up:</B> <A NAME="tex2html9029" HREF="node491.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node491.html">36.1 Using application-level data</A><B> Previous:</B> <A NAME="tex2html9023" HREF="node494.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node494.html">36.1.3 Transmitting user data</A>   <B> <A NAME="tex2html9031" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html9033" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <!--End of Navigation Panel--><ADDRESS>2003-09-23</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -