Include dependency graph for tcp_half_duplex_client.c:</div>
<divclass="dyncontent">
<divclass="center"><divclass="zoom"><iframescrolling="no"frameborder="0"src="../../dd/deb/tcp__half__duplex__client_8c__incl.svg"width="100%"height="395"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<trclass="memdesc:a614217d263be1fb1a5f76e2ff7be19a2"><tdclass="mdescLeft"> </td><tdclass="mdescRight">For structures returned by the network database library - formatted internet addresses and port numbers For in_addr and sockaddr_in structures. <ahref="../../da/d07/tcp__half__duplex__client_8c.html#a614217d263be1fb1a5f76e2ff7be19a2">More...</a><br/></td></tr>
<trclass="memdesc:a7e15c8e2885871839fc2b820dfbdb4ce"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Utility function used to print an error message to <code>stderr</code>. <ahref="../../da/d07/tcp__half__duplex__client_8c.html#a7e15c8e2885871839fc2b820dfbdb4ce">More...</a><br/></td></tr>
<dlclass="section see"><dt>See also</dt><dd><aclass="el"href="../../d6/d2b/tcp__half__duplex__server_8c.html"title="Server-side implementation of TCP Half Duplex Communication">tcp_half_duplex_server.c</a></dd></dl>
<p>The algorithm is based on the simple TCP client and server model. However, instead of the server only sending and the client only receiving data, the server and client can both send data but only one at a time. This is implemented by using a particular ordering of the <code>send()</code> and <code>recv()</code> functions. When one of the clients or servers is sending, the other can only receive and vice-versa. In this way, the Half Duplex Form of communication can be represented using the TCP server-client model & socket programming </p>
<p>For structures returned by the network database library - formatted internet addresses and port numbers For in_addr and sockaddr_in structures. </p>
<p>For specific bit size values of variables Variable types, several macros, and various functions for performing input and output Variable types, several macros, and various functions for performing general functions Various functions for manipulating arrays of characters For macro definitions related to the creation of sockets For definitions to allow for the porting of BSD programs For miscellaneous symbolic constants and types, and miscellaneous functions </p>
<p>Utility function used to print an error message to <code>stderr</code>. </p>
<p>It prints <code>str</code> and an implementation-defined error message corresponding to the global variable <code>errno</code>. </p><dlclass="section return"><dt>Returns</dt><dd>void </dd></dl>
<dlclass="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<p>Variable Declarations</p>
<p>< socket descriptors - Like file handles but for sockets</p>
<p>< basic structures for all syscalls and functions that deal with internet addresses. Structures for handling internet addresses</p>
<p>< Character arrays to read and store string data for communication</p>
<p>The TCP socket is created using the socket function.</p>
<p>AF_INET (Family) - it is an address family that is used to designate the type of addresses that your socket can communicate with</p>
<p>SOCK_STREAM (Type) - Indicates TCP Connection - A stream socket provides for the bidirectional, reliable, sequenced, and unduplicated flow of data without record boundaries. Aside from the bidirectionality of data flow, a pair of connected stream sockets provides an interface nearly identical to pipes.</p>
<p>0 (Protocol) - Specifies a particular protocol to be used with the socket. Specifying a protocol of 0 causes socket() to use an unspecified default protocol appropriate for the requested socket type.</p>
<p>Server Address Information</p>
<p>The bzero() function erases the data in the n bytes of the memory starting at the location pointed to, by writing zeros (bytes containing '\0') to that area.</p>
<p>We bind the server_addr to the internet address and port number thus giving our socket an identity with an address and port where it can listen for connections</p>
<p>htons - The htons() function translates a short integer from host byte order to network byte order</p>
<p>htonl - The htonl() function translates a long integer from host byte order to network byte order</p>
<p>These functions are necessary so that the binding of address and port takes place with data in the correct format</p>
<p>Connects the client to the server address using the socket descriptor This enables the two to communicate and exchange data</p>
<p>Communication between client and server</p>
<p>The bzero() function erases the data in the n bytes of the memory starting at the location pointed to, by writing zeros (bytes containing '\0') to that area. The variables are emptied and then ready for use</p>
<p>First the CLIENT receives the servers message and displays it (recv())</p>
<p>The CLIENT is then prompted to type in a message and send it to the server. (send())</p>
<p>The server and client can communicate till one of them exits the connection</p>
<p>Since the exchange of information between the server and client take place one at a time this represents HALF DUPLEX COMMUNICATION</p>
<divclass="line"><aid="l00050"name="l00050"></a><spanclass="lineno"> 50</span> sockfd; <spanclass="comment">///< socket descriptors - Like file handles but for sockets</span></div>
<divclass="line"><aid="l00052"name="l00052"></a><spanclass="lineno"> 52</span> server_addr; <spanclass="comment">///< basic structures for all syscalls and functions that</span><spanclass="comment"></span></div>
<divclass="line"><aid="l00053"name="l00053"></a><spanclass="lineno"> 53</span><spanclass="comment"> /// deal with internet addresses. Structures for handling</span></div>
<divclass="line"><aid="l00054"name="l00054"></a><spanclass="lineno"> 54</span><spanclass="comment"> /// internet addresses</span></div>
<divclass="line"><aid="l00056"name="l00056"></a><spanclass="lineno"> 56</span> clientResponse[10000]; <spanclass="comment">///< Character arrays to read and store string</span><spanclass="comment"></span></div>
<divclass="line"><aid="l00057"name="l00057"></a><spanclass="lineno"> 57</span><spanclass="comment"> /// data for communication</span></div>
<divclass="line"><aid="l00060"name="l00060"></a><spanclass="lineno"> 60</span><spanclass="comment"> * The TCP socket is created using the socket function.</span></div>
<divclass="line"><aid="l00062"name="l00062"></a><spanclass="lineno"> 62</span><spanclass="comment"> * AF_INET (Family) - it is an address family that is used to designate the</span></div>
<divclass="line"><aid="l00063"name="l00063"></a><spanclass="lineno"> 63</span><spanclass="comment"> * type of addresses that your socket can communicate with</span></div>
<divclass="line"><aid="l00066"name="l00066"></a><spanclass="lineno"> 66</span><spanclass="comment"> * for the bidirectional, reliable, sequenced, and unduplicated flow of data</span></div>
<divclass="line"><aid="l00067"name="l00067"></a><spanclass="lineno"> 67</span><spanclass="comment"> * without record boundaries. Aside from the bidirectionality of data flow,</span></div>
<divclass="line"><aid="l00068"name="l00068"></a><spanclass="lineno"> 68</span><spanclass="comment"> * a pair of connected stream sockets provides an interface nearly identical</span></div>
<divclass="line"><aid="l00069"name="l00069"></a><spanclass="lineno"> 69</span><spanclass="comment"> * to pipes.</span></div>
<divclass="line"><aid="l00071"name="l00071"></a><spanclass="lineno"> 71</span><spanclass="comment"> * 0 (Protocol) - Specifies a particular protocol to be used with the</span></div>
<divclass="line"><aid="l00072"name="l00072"></a><spanclass="lineno"> 72</span><spanclass="comment"> * socket. Specifying a protocol of 0 causes socket() to use an unspecified</span></div>
<divclass="line"><aid="l00073"name="l00073"></a><spanclass="lineno"> 73</span><spanclass="comment"> * default protocol appropriate for the requested socket type.</span></div>
<divclass="line"><aid="l00083"name="l00083"></a><spanclass="lineno"> 83</span><spanclass="comment"> * The bzero() function erases the data in the n bytes of the memory</span></div>
<divclass="line"><aid="l00084"name="l00084"></a><spanclass="lineno"> 84</span><spanclass="comment"> * starting at the location pointed to, by writing zeros (bytes</span></div>
<divclass="line"><aid="l00085"name="l00085"></a><spanclass="lineno"> 85</span><spanclass="comment"> * containing '\0') to that area.</span></div>
<divclass="line"><aid="l00087"name="l00087"></a><spanclass="lineno"> 87</span><spanclass="comment"> * We bind the server_addr to the internet address and port number thus</span></div>
<divclass="line"><aid="l00088"name="l00088"></a><spanclass="lineno"> 88</span><spanclass="comment"> * giving our socket an identity with an address and port where it can</span></div>
<divclass="line"><aid="l00089"name="l00089"></a><spanclass="lineno"> 89</span><spanclass="comment"> * listen for connections</span></div>
<divclass="line"><aid="l00091"name="l00091"></a><spanclass="lineno"> 91</span><spanclass="comment"> * htons - The htons() function translates a short integer from host byte</span></div>
<divclass="line"><aid="l00092"name="l00092"></a><spanclass="lineno"> 92</span><spanclass="comment"> * order to network byte order</span></div>
<divclass="line"><aid="l00094"name="l00094"></a><spanclass="lineno"> 94</span><spanclass="comment"> * htonl - The htonl() function translates a long integer from host byte</span></div>
<divclass="line"><aid="l00095"name="l00095"></a><spanclass="lineno"> 95</span><spanclass="comment"> * order to network byte order</span></div>
<divclass="line"><aid="l00097"name="l00097"></a><spanclass="lineno"> 97</span><spanclass="comment"> * These functions are necessary so that the binding of address and port</span></div>
<divclass="line"><aid="l00098"name="l00098"></a><spanclass="lineno"> 98</span><spanclass="comment"> * takes place with data in the correct format</span></div>
<divclass="line"><aid="l00105"name="l00105"></a><spanclass="lineno"> 105</span> printf(<spanclass="stringliteral">"Client is running...\n"</span>);</div>
<divclass="line"><aid="l00108"name="l00108"></a><spanclass="lineno"> 108</span><spanclass="comment"> * Connects the client to the server address using the socket descriptor</span></div>
<divclass="line"><aid="l00109"name="l00109"></a><spanclass="lineno"> 109</span><spanclass="comment"> * This enables the two to communicate and exchange data</span></div>
<divclass="line"><aid="l00113"name="l00113"></a><spanclass="lineno"> 113</span> printf(<spanclass="stringliteral">"Client is connected...\n"</span>);</div>
<divclass="line"><aid="l00116"name="l00116"></a><spanclass="lineno"> 116</span><spanclass="comment"> * Communication between client and server</span></div>
<divclass="line"><aid="l00118"name="l00118"></a><spanclass="lineno"> 118</span><spanclass="comment"> * The bzero() function erases the data in the n bytes of the memory</span></div>
<divclass="line"><aid="l00119"name="l00119"></a><spanclass="lineno"> 119</span><spanclass="comment"> * starting at the location pointed to, by writing zeros (bytes</span></div>
<divclass="line"><aid="l00120"name="l00120"></a><spanclass="lineno"> 120</span><spanclass="comment"> * containing '\0') to that area. The variables are emptied and then</span></div>
<divclass="line"><aid="l00121"name="l00121"></a><spanclass="lineno"> 121</span><spanclass="comment"> * ready for use</span></div>
<divclass="line"><aid="l00123"name="l00123"></a><spanclass="lineno"> 123</span><spanclass="comment"> * First the CLIENT receives the servers message and displays it (recv())</span></div>
<divclass="line"><aid="l00125"name="l00125"></a><spanclass="lineno"> 125</span><spanclass="comment"> * The CLIENT is then prompted to type in a message and send it to the</span></div>
<divclass="line"><aid="l00128"name="l00128"></a><spanclass="lineno"> 128</span><spanclass="comment"> * The server and client can communicate till one of them exits the</span></div>
<divclass="line"><aid="l00131"name="l00131"></a><spanclass="lineno"> 131</span><spanclass="comment"> * Since the exchange of information between the server and client take</span></div>
<divclass="line"><aid="l00132"name="l00132"></a><spanclass="lineno"> 132</span><spanclass="comment"> * place one at a time this represents HALF DUPLEX COMMUNICATION</span></div>
<divclass="line"><aid="l00151"name="l00151"></a><spanclass="lineno"> 151</span> printf(<spanclass="stringliteral">"Client is offline...\n"</span>);</div>
<divclass="ttc"id="atcp__half__duplex__client_8c_html_a614217d263be1fb1a5f76e2ff7be19a2"><divclass="ttname"><ahref="../../da/d07/tcp__half__duplex__client_8c.html#a614217d263be1fb1a5f76e2ff7be19a2">PORT</a></div><divclass="ttdeci">#define PORT</div><divclass="ttdoc">For structures returned by the network database library - formatted internet addresses and port numbe...</div><divclass="ttdef"><b>Definition:</b> tcp_half_duplex_client.c:28</div></div>
<divclass="ttc"id="atcp__half__duplex__client_8c_html_a7e15c8e2885871839fc2b820dfbdb4ce"><divclass="ttname"><ahref="../../da/d07/tcp__half__duplex__client_8c.html#a7e15c8e2885871839fc2b820dfbdb4ce">error</a></div><divclass="ttdeci">void error()</div><divclass="ttdoc">Utility function used to print an error message to stderr.</div><divclass="ttdef"><b>Definition:</b> tcp_half_duplex_client.c:36</div></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/d07/tcp__half__duplex__client_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg"width="158"height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<liclass="footer">Generated by <ahref="https://www.doxygen.org/index.html"><imgclass="footer"src="../../doxygen.svg"width="104"height="31"alt="doxygen"/></a> 1.9.2 </li>