root/doc/html/tcp__client__server_8h-source.html @ 353

Revision 353, 14.4 kB (checked in by smidl, 16 years ago)

doc

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3<title>mixpp: tcp_client_server.h Source File</title>
4<link href="tabs.css" rel="stylesheet" type="text/css">
5<link href="doxygen.css" rel="stylesheet" type="text/css">
6</head><body>
7<!-- Generated by Doxygen 1.5.8 -->
8<script type="text/javascript">
9<!--
10function changeDisplayState (e){
11  var num=this.id.replace(/[^[0-9]/g,'');
12  var button=this.firstChild;
13  var sectionDiv=document.getElementById('dynsection'+num);
14  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
15    sectionDiv.style.display='block';
16    button.src='open.gif';
17  }else{
18    sectionDiv.style.display='none';
19    button.src='closed.gif';
20  }
21}
22function initDynSections(){
23  var divs=document.getElementsByTagName('div');
24  var sectionCounter=1;
25  for(var i=0;i<divs.length-1;i++){
26    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
27      var header=divs[i];
28      var section=divs[i+1];
29      var button=header.firstChild;
30      if (button!='IMG'){
31        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
32        button=document.createElement('img');
33        divs[i].insertBefore(button,divs[i].firstChild);
34      }
35      header.style.cursor='pointer';
36      header.onclick=changeDisplayState;
37      header.id='dynheader'+sectionCounter;
38      button.src='closed.gif';
39      section.id='dynsection'+sectionCounter;
40      section.style.display='none';
41      section.style.marginLeft='14px';
42      sectionCounter++;
43    }
44  }
45}
46window.onload = initDynSections;
47-->
48</script>
49<div class="navigation" id="top">
50  <div class="tabs">
51    <ul>
52      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
53      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
54      <li><a href="modules.html"><span>Modules</span></a></li>
55      <li><a href="annotated.html"><span>Classes</span></a></li>
56      <li class="current"><a href="files.html"><span>Files</span></a></li>
57    </ul>
58  </div>
59  <div class="tabs">
60    <ul>
61      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
62      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
63    </ul>
64  </div>
65<h1>tcp_client_server.h</h1><a href="tcp__client__server_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
66<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;<a class="code" href="tcp_8h.html" title="Definition of Transport Control Protocol (TCP).">itpp/protocol/tcp.h</a>&gt;</span>
67<a name="l00030"></a>00030
68<a name="l00031"></a>00031
69<a name="l00032"></a>00032 <span class="keyword">namespace </span>itpp
70<a name="l00033"></a>00033 {
71<a name="l00034"></a>00034
72<a name="l00036"></a>00036
73<a name="l00037"></a>00037
74<a name="l00041"></a><a class="code" href="classitpp_1_1TCP__Server__Application.html">00041</a> <span class="keyword">class </span><a class="code" href="classitpp_1_1TCP__Server__Application.html">TCP_Server_Application</a>
75<a name="l00042"></a>00042 {
76<a name="l00043"></a>00043 <span class="keyword">public</span>:
77<a name="l00045"></a><a class="code" href="classitpp_1_1TCP__Server__Application.html#e83e00302965be811f437eddcc5842f1">00045</a>   <a class="code" href="classitpp_1_1TCP__Server__Application.html#e83e00302965be811f437eddcc5842f1" title="Default constructor.">TCP_Server_Application</a>() {
78<a name="l00046"></a>00046     <a class="code" href="classitpp_1_1TCP__Server__Application.html#f81d0ae85186d21c940ce3c5ed11c34f" title="ADD DOCUMENTATION HERE.">write</a>.<a class="code" href="group__protocol.html#g02061d18d1b74311f2fc3b6bc0005b22" title="set name of signal">set_name</a>(<span class="stringliteral">"TcpServerApplicationWriteSignal"</span>);
79<a name="l00047"></a>00047     <a class="code" href="classitpp_1_1TCP__Server__Application.html#f81d0ae85186d21c940ce3c5ed11c34f" title="ADD DOCUMENTATION HERE.">write</a>.<a class="code" href="group__protocol.html#g7726292b50426ec743036cfaceb85229" title="Set debug mode. If true all signals are printed to stdout.">set_debug</a>();
80<a name="l00048"></a>00048   }
81<a name="l00050"></a><a class="code" href="classitpp_1_1TCP__Server__Application.html#71f6f8712f15bda287d411b2f2451657">00050</a>   <a class="code" href="classitpp_1_1TCP__Server__Application.html#71f6f8712f15bda287d411b2f2451657" title="Destructor.">~TCP_Server_Application</a>() { }
82<a name="l00051"></a>00051
83<a name="l00053"></a><a class="code" href="classitpp_1_1TCP__Server__Application.html#f81d0ae85186d21c940ce3c5ed11c34f">00053</a>   <a class="code" href="classitpp_1_1Signal.html">Signal&lt;itpp::Packet*&gt;</a> <a class="code" href="classitpp_1_1TCP__Server__Application.html#f81d0ae85186d21c940ce3c5ed11c34f" title="ADD DOCUMENTATION HERE.">write</a>;
84<a name="l00054"></a>00054
85<a name="l00056"></a><a class="code" href="classitpp_1_1TCP__Server__Application.html#088c20f857ceb8f065633dd992416f19">00056</a>   <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1TCP__Server__Application.html#088c20f857ceb8f065633dd992416f19" title="ADD DOCUMENTATION HERE.">write_to_net</a>(<span class="keywordtype">unsigned</span> byte_size, <span class="keywordtype">double</span> delta_time) {
86<a name="l00057"></a>00057     <a class="code" href="classitpp_1_1Packet.html">itpp::Packet</a> *packet = <span class="keyword">new</span> <a class="code" href="classitpp_1_1Packet.html">Packet</a>(8*byte_size);
87<a name="l00058"></a>00058     <a class="code" href="classitpp_1_1TCP__Server__Application.html#f81d0ae85186d21c940ce3c5ed11c34f" title="ADD DOCUMENTATION HERE.">write</a>(packet, delta_time);
88<a name="l00059"></a>00059
89<a name="l00060"></a>00060     std::cout &lt;&lt; <span class="stringliteral">"TcpServerApplication::write_to_net,"</span>
90<a name="l00061"></a>00061               &lt;&lt; <span class="stringliteral">" byte_size="</span> &lt;&lt; packet-&gt;<a class="code" href="classitpp_1_1Packet.html#2970c5562530cf8981965451a5dde65a" title="get size of packet in bits">bit_size</a>() / 8
91<a name="l00062"></a>00062               &lt;&lt; <span class="stringliteral">" ptr="</span> &lt;&lt; packet
92<a name="l00063"></a>00063               &lt;&lt; <span class="stringliteral">" time="</span> &lt;&lt; <a class="code" href="classitpp_1_1Event__Queue.html#ac4b417979ddc31b7588602a3c1438e6" title="Return current time.">Event_Queue::now</a>() &lt;&lt; std::endl;
93<a name="l00064"></a>00064   }
94<a name="l00065"></a>00065 };
95<a name="l00066"></a>00066
96<a name="l00070"></a><a class="code" href="classitpp_1_1TCP__Client__Application.html">00070</a> <span class="keyword">class </span><a class="code" href="classitpp_1_1TCP__Client__Application.html">TCP_Client_Application</a>
97<a name="l00071"></a>00071 {
98<a name="l00072"></a>00072 <span class="keyword">public</span>:
99<a name="l00074"></a><a class="code" href="classitpp_1_1TCP__Client__Application.html#f7f15d5942a5cedcfbd87e085ee40c5b">00074</a>   <a class="code" href="classitpp_1_1TCP__Client__Application.html#f7f15d5942a5cedcfbd87e085ee40c5b" title="Default constructor.">TCP_Client_Application</a>(<a class="code" href="classitpp_1_1TCP__Sender.html">TCP_Sender</a> *tcp_snd_p, <a class="code" href="classitpp_1_1TCP__Receiver.html">TCP_Receiver</a> *tcp_recv_p) {
100<a name="l00075"></a>00075     tcp_receiver_p = tcp_recv_p;
101<a name="l00076"></a>00076     tcp_sender_p = tcp_snd_p;
102<a name="l00077"></a>00077     nbr_bytes_received = 0;
103<a name="l00078"></a>00078     <a class="code" href="classitpp_1_1TCP__Client__Application.html#140925c85d1a573cdb1ffb08065e0076" title="ADD DOCUMENTATION HERE.">select</a>.<a class="code" href="group__protocol.html#gd1dc9e2216a8e4f623efa1201781200e" title="ADD DOCUMENTATION HERE.">forward</a>(<span class="keyword">this</span>, &amp;TCP_Client_Application::received_packet_indication);
104<a name="l00079"></a>00079     <a class="code" href="classitpp_1_1TCP__Client__Application.html#140925c85d1a573cdb1ffb08065e0076" title="ADD DOCUMENTATION HERE.">select</a>.<a class="code" href="group__protocol.html#gb7ab2e7102400aaddc25b4d2391a362c" title="set slot name">set_name</a>(<span class="stringliteral">"TcpClientApplicationSelectSlot"</span>);
105<a name="l00080"></a>00080     seq_num_index = 0;
106<a name="l00081"></a>00081   }
107<a name="l00082"></a>00082
108<a name="l00084"></a><a class="code" href="classitpp_1_1TCP__Client__Application.html#61bd7e20d7849b339fc6735658eb3340">00084</a>   <a class="code" href="classitpp_1_1TCP__Client__Application.html#61bd7e20d7849b339fc6735658eb3340" title="Destructor.">~TCP_Client_Application</a>() { }
109<a name="l00085"></a>00085
110<a name="l00087"></a><a class="code" href="classitpp_1_1TCP__Client__Application.html#140925c85d1a573cdb1ffb08065e0076">00087</a>   <a class="code" href="classitpp_1_1Slot.html">Slot&lt;TCP_Client_Application, int&gt;</a> <a class="code" href="classitpp_1_1TCP__Client__Application.html#140925c85d1a573cdb1ffb08065e0076" title="ADD DOCUMENTATION HERE.">select</a>;
111<a name="l00088"></a>00088
112<a name="l00090"></a><a class="code" href="classitpp_1_1TCP__Client__Application.html#7ec5c489a463d5796db446525fb515fb">00090</a>   <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1TCP__Client__Application.html#7ec5c489a463d5796db446525fb515fb" title="ADD DOCUMENTATION HERE.">read_from_net</a>(<span class="keywordtype">unsigned</span> byte_size) {
113<a name="l00091"></a>00091     nbr_bytes_to_receive = byte_size;
114<a name="l00092"></a>00092     seq_num_val.set_size(10 + byte_size / 1460);
115<a name="l00093"></a>00093     seq_num_val.zeros();
116<a name="l00094"></a>00094     seq_num_time.set_size(10 + byte_size / 1460);
117<a name="l00095"></a>00095     seq_num_time.zeros();
118<a name="l00096"></a>00096     seq_num_val(0) = 0;
119<a name="l00097"></a>00097     seq_num_time(0) = 0;
120<a name="l00098"></a>00098     seq_num_index = 1;
121<a name="l00099"></a>00099   };
122<a name="l00100"></a>00100
123<a name="l00101"></a>00101 <span class="keyword">private</span>:
124<a name="l00102"></a>00102   <a class="code" href="classitpp_1_1TCP__Receiver.html">TCP_Receiver</a> *tcp_receiver_p;
125<a name="l00103"></a>00103   <a class="code" href="classitpp_1_1TCP__Sender.html">TCP_Sender</a> *tcp_sender_p;
126<a name="l00104"></a>00104   <span class="keywordtype">unsigned</span> nbr_bytes_received;
127<a name="l00105"></a>00105   <span class="keywordtype">unsigned</span> nbr_bytes_to_receive;
128<a name="l00106"></a>00106
129<a name="l00107"></a>00107   vec seq_num_val;
130<a name="l00108"></a>00108   vec seq_num_time;
131<a name="l00109"></a>00109   <span class="keywordtype">int</span> seq_num_index;
132<a name="l00110"></a>00110
133<a name="l00111"></a>00111   <span class="keywordtype">void</span> TCP_Client_Application::received_packet_indication(<span class="keywordtype">int</span> label) {
134<a name="l00112"></a>00112
135<a name="l00113"></a>00113     <a class="code" href="classitpp_1_1Packet.html">itpp::Packet</a> &amp;packet = tcp_receiver_p-&gt;<a class="code" href="classitpp_1_1TCP__Receiver.html#f0755a2cd71399c37a5a2bf6a12dd42c" title="called by higher layer">get_user_message</a>();
136<a name="l00114"></a>00114     nbr_bytes_received = nbr_bytes_received + packet.<a class="code" href="classitpp_1_1Packet.html#2970c5562530cf8981965451a5dde65a" title="get size of packet in bits">bit_size</a>() / 8;
137<a name="l00115"></a>00115     <span class="keyword">delete</span> &amp;packet;
138<a name="l00116"></a>00116
139<a name="l00117"></a>00117     <span class="keywordflow">if</span> (seq_num_index &gt;= seq_num_time.size()) {
140<a name="l00118"></a>00118       seq_num_time.set_size(2*seq_num_time.size(), <span class="keyword">true</span>);
141<a name="l00119"></a>00119       seq_num_val.set_size(2*seq_num_val.size(), <span class="keyword">true</span>);
142<a name="l00120"></a>00120     }
143<a name="l00121"></a>00121
144<a name="l00122"></a>00122     seq_num_val(seq_num_index) = nbr_bytes_received;
145<a name="l00123"></a>00123     seq_num_time(seq_num_index) = <a class="code" href="classitpp_1_1Event__Queue.html#ac4b417979ddc31b7588602a3c1438e6" title="Return current time.">Event_Queue::now</a>();
146<a name="l00124"></a>00124     seq_num_index++;
147<a name="l00125"></a>00125
148<a name="l00126"></a>00126     std::cout &lt;&lt; <span class="stringliteral">"### sequence number: "</span> &lt;&lt; nbr_bytes_received
149<a name="l00127"></a>00127               &lt;&lt; <span class="stringliteral">" ### time:"</span> &lt;&lt; <a class="code" href="classitpp_1_1Event__Queue.html#ac4b417979ddc31b7588602a3c1438e6" title="Return current time.">Event_Queue::now</a>() &lt;&lt; std::endl;
150<a name="l00128"></a>00128
151<a name="l00129"></a>00129     <span class="keywordflow">if</span> (nbr_bytes_received &gt;= nbr_bytes_to_receive) {
152<a name="l00130"></a>00130       std::cout &lt;&lt; <span class="stringliteral">"###### Stop sender and receiver"</span> &lt;&lt; std::endl;
153<a name="l00131"></a>00131       tcp_receiver_p-&gt;release();
154<a name="l00132"></a>00132       tcp_sender_p-&gt;release();
155<a name="l00133"></a>00133       tcp_sender_p-&gt;save_trace(<span class="stringliteral">"seq_num.it"</span>);
156<a name="l00134"></a>00134       seq_num_val.set_size(seq_num_index, <span class="keyword">true</span>);
157<a name="l00135"></a>00135       seq_num_time.set_size(seq_num_index, <span class="keyword">true</span>);
158<a name="l00136"></a>00136       save_to_file(<span class="stringliteral">"seq_num.it"</span>);
159<a name="l00137"></a>00137     }
160<a name="l00138"></a>00138   }
161<a name="l00139"></a>00139
162<a name="l00140"></a>00140   <span class="keywordtype">void</span> TCP_Client_Application::save_to_file(<span class="keywordtype">string</span> file) {
163<a name="l00141"></a>00141
164<a name="l00142"></a>00142     it_file ff2(file);
165<a name="l00143"></a>00143     ff2 &lt;&lt; Name(<span class="stringliteral">"seq_num_val"</span>) &lt;&lt; seq_num_val;
166<a name="l00144"></a>00144     ff2 &lt;&lt; Name(<span class="stringliteral">"seq_num_time"</span>) &lt;&lt; seq_num_time;
167<a name="l00145"></a>00145     ff2 &lt;&lt; Name(<span class="stringliteral">"seq_num_index"</span>) &lt;&lt; seq_num_index;
168<a name="l00146"></a>00146     ff2.flush();
169<a name="l00147"></a>00147     ff2.close();
170<a name="l00148"></a>00148   }
171<a name="l00149"></a>00149
172<a name="l00150"></a>00150 };
173<a name="l00151"></a>00151
174<a name="l00153"></a>00153
175<a name="l00154"></a>00154 } <span class="comment">// namespace itpp</span>
176</pre></div></div>
177<hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 2 10:02:13 2009 for mixpp by&nbsp;
178<a href="http://www.doxygen.org/index.html">
179<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
180</body>
181</html>
Note: See TracBrowser for help on using the browser.