TheAlgorithms-C/da/d07/tcp__half__duplex__client_8c.html
2022-09-08 00:17:03 +00:00

359 lines
29 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.5"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C: client_server/tcp_half_duplex_client.c File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">Algorithms_in_C<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.5 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('da/d07/tcp__half__duplex__client_8c.html','../../'); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="summary">
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle"><div class="title">tcp_half_duplex_client.c File Reference</div></div>
</div><!--header-->
<div class="contents">
<p>Client-side implementation of <a href="http://www.tcpipguide.com/free/t_SimplexFullDuplexandHalfDuplexOperation.htm" target="_blank">TCP Half Duplex Communication</a>
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;netdb.h&gt;</code><br />
<code>#include &lt;netinet/in.h&gt;</code><br />
<code>#include &lt;stdint.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;string.h&gt;</code><br />
<code>#include &lt;sys/socket.h&gt;</code><br />
<code>#include &lt;sys/types.h&gt;</code><br />
<code>#include &lt;unistd.h&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for tcp_half_duplex_client.c:</div>
<div class="dyncontent">
<div class="center"><div class="zoom"><iframe scrolling="no" frameborder="0" src="../../dd/deb/tcp__half__duplex__client_8c__incl.svg" width="100%" height="393"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="define-members" name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:a614217d263be1fb1a5f76e2ff7be19a2"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d07/tcp__half__duplex__client_8c.html#a614217d263be1fb1a5f76e2ff7be19a2">PORT</a>&#160;&#160;&#160;8100</td></tr>
<tr class="memdesc:a614217d263be1fb1a5f76e2ff7be19a2"><td class="mdescLeft">&#160;</td><td class="mdescRight">For structures returned by the network database library - formatted internet addresses and port numbers For in_addr and sockaddr_in structures. <a href="../../da/d07/tcp__half__duplex__client_8c.html#a614217d263be1fb1a5f76e2ff7be19a2">More...</a><br /></td></tr>
<tr class="separator:a614217d263be1fb1a5f76e2ff7be19a2"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a7e15c8e2885871839fc2b820dfbdb4ce"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d07/tcp__half__duplex__client_8c.html#a7e15c8e2885871839fc2b820dfbdb4ce">error</a> ()</td></tr>
<tr class="memdesc:a7e15c8e2885871839fc2b820dfbdb4ce"><td class="mdescLeft">&#160;</td><td class="mdescRight">Utility function used to print an error message to <code>stderr</code>. <a href="../../da/d07/tcp__half__duplex__client_8c.html#a7e15c8e2885871839fc2b820dfbdb4ce">More...</a><br /></td></tr>
<tr class="separator:a7e15c8e2885871839fc2b820dfbdb4ce"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d07/tcp__half__duplex__client_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <a href="../../da/d07/tcp__half__duplex__client_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Client-side implementation of <a href="http://www.tcpipguide.com/free/t_SimplexFullDuplexandHalfDuplexOperation.htm" target="_blank">TCP Half Duplex Communication</a> </p>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/NVombat" target="_blank">Nikhill Vombatkere</a> </dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="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 &amp; socket programming </p>
</div><h2 class="groupheader">Macro Definition Documentation</h2>
<a id="a614217d263be1fb1a5f76e2ff7be19a2" name="a614217d263be1fb1a5f76e2ff7be19a2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a614217d263be1fb1a5f76e2ff7be19a2">&#9670;&#160;</a></span>PORT</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define PORT&#160;&#160;&#160;8100</td>
</tr>
</table>
</div><div class="memdoc">
<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>
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="a7e15c8e2885871839fc2b820dfbdb4ce" name="a7e15c8e2885871839fc2b820dfbdb4ce"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7e15c8e2885871839fc2b820dfbdb4ce">&#9670;&#160;</a></span>error()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void error </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<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><dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 37</span>{</div>
<div class="line"><span class="lineno"> 38</span> perror(<span class="stringliteral">&quot;Socket Creation Failed&quot;</span>);</div>
<div class="line"><span class="lineno"> 39</span> exit(EXIT_FAILURE);</div>
<div class="line"><span class="lineno"> 40</span>}</div>
</div><!-- fragment -->
</div>
</div>
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&#160;</a></span>main()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int main </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Main function. </p>
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<p >Variable Declarations</p>
<p >&lt; socket descriptors - Like file handles but for sockets</p>
<p >&lt; basic structures for all syscalls and functions that deal with internet addresses. Structures for handling internet addresses</p>
<p >&lt; 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>
<p >Receive Message</p>
<p >Send Message</p>
<p >Close Socket</p>
<div class="fragment"><div class="line"><span class="lineno"> 47</span>{<span class="comment"></span></div>
<div class="line"><span class="lineno"> 48</span><span class="comment"> /** Variable Declarations */</span></div>
<div class="line"><span class="lineno"> 49</span> uint32_t</div>
<div class="line"><span class="lineno"> 50</span> sockfd; <span class="comment">///&lt; socket descriptors - Like file handles but for sockets</span></div>
<div class="line"><span class="lineno"> 51</span> <span class="keyword">struct </span>sockaddr_in</div>
<div class="line"><span class="lineno"> 52</span> server_addr; <span class="comment">///&lt; basic structures for all syscalls and functions that</span><span class="comment"></span></div>
<div class="line"><span class="lineno"> 53</span><span class="comment"> /// deal with internet addresses. Structures for handling</span></div>
<div class="line"><span class="lineno"> 54</span><span class="comment"> /// internet addresses</span></div>
<div class="line"><span class="lineno"> 55</span><span class="comment"></span> <span class="keywordtype">char</span> serverResponse[10000],</div>
<div class="line"><span class="lineno"> 56</span> clientResponse[10000]; <span class="comment">///&lt; Character arrays to read and store string</span><span class="comment"></span></div>
<div class="line"><span class="lineno"> 57</span><span class="comment"> /// data for communication</span></div>
<div class="line"><span class="lineno"> 58</span><span class="comment"></span><span class="comment"></span> </div>
<div class="line"><span class="lineno"> 59</span><span class="comment"> /**</span></div>
<div class="line"><span class="lineno"> 60</span><span class="comment"> * The TCP socket is created using the socket function.</span></div>
<div class="line"><span class="lineno"> 61</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 62</span><span class="comment"> * AF_INET (Family) - it is an address family that is used to designate the</span></div>
<div class="line"><span class="lineno"> 63</span><span class="comment"> * type of addresses that your socket can communicate with</span></div>
<div class="line"><span class="lineno"> 64</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 65</span><span class="comment"> * SOCK_STREAM (Type) - Indicates TCP Connection - A stream socket provides</span></div>
<div class="line"><span class="lineno"> 66</span><span class="comment"> * for the bidirectional, reliable, sequenced, and unduplicated flow of data</span></div>
<div class="line"><span class="lineno"> 67</span><span class="comment"> * without record boundaries. Aside from the bidirectionality of data flow,</span></div>
<div class="line"><span class="lineno"> 68</span><span class="comment"> * a pair of connected stream sockets provides an interface nearly identical</span></div>
<div class="line"><span class="lineno"> 69</span><span class="comment"> * to pipes.</span></div>
<div class="line"><span class="lineno"> 70</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 71</span><span class="comment"> * 0 (Protocol) - Specifies a particular protocol to be used with the</span></div>
<div class="line"><span class="lineno"> 72</span><span class="comment"> * socket. Specifying a protocol of 0 causes socket() to use an unspecified</span></div>
<div class="line"><span class="lineno"> 73</span><span class="comment"> * default protocol appropriate for the requested socket type.</span></div>
<div class="line"><span class="lineno"> 74</span><span class="comment"> */</span></div>
<div class="line"><span class="lineno"> 75</span> <span class="keywordflow">if</span> ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0)</div>
<div class="line"><span class="lineno"> 76</span> {</div>
<div class="line"><span class="lineno"> 77</span> <a class="code hl_function" href="../../da/d07/tcp__half__duplex__client_8c.html#a7e15c8e2885871839fc2b820dfbdb4ce">error</a>();</div>
<div class="line"><span class="lineno"> 78</span> }</div>
<div class="line"><span class="lineno"> 79</span><span class="comment"></span> </div>
<div class="line"><span class="lineno"> 80</span><span class="comment"> /**</span></div>
<div class="line"><span class="lineno"> 81</span><span class="comment"> * Server Address Information</span></div>
<div class="line"><span class="lineno"> 82</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 83</span><span class="comment"> * The bzero() function erases the data in the n bytes of the memory</span></div>
<div class="line"><span class="lineno"> 84</span><span class="comment"> * starting at the location pointed to, by writing zeros (bytes</span></div>
<div class="line"><span class="lineno"> 85</span><span class="comment"> * containing &#39;\0&#39;) to that area.</span></div>
<div class="line"><span class="lineno"> 86</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 87</span><span class="comment"> * We bind the server_addr to the internet address and port number thus</span></div>
<div class="line"><span class="lineno"> 88</span><span class="comment"> * giving our socket an identity with an address and port where it can</span></div>
<div class="line"><span class="lineno"> 89</span><span class="comment"> * listen for connections</span></div>
<div class="line"><span class="lineno"> 90</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 91</span><span class="comment"> * htons - The htons() function translates a short integer from host byte</span></div>
<div class="line"><span class="lineno"> 92</span><span class="comment"> * order to network byte order</span></div>
<div class="line"><span class="lineno"> 93</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 94</span><span class="comment"> * htonl - The htonl() function translates a long integer from host byte</span></div>
<div class="line"><span class="lineno"> 95</span><span class="comment"> * order to network byte order</span></div>
<div class="line"><span class="lineno"> 96</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 97</span><span class="comment"> * These functions are necessary so that the binding of address and port</span></div>
<div class="line"><span class="lineno"> 98</span><span class="comment"> * takes place with data in the correct format</span></div>
<div class="line"><span class="lineno"> 99</span><span class="comment"> */</span></div>
<div class="line"><span class="lineno"> 100</span> bzero(&amp;server_addr, <span class="keyword">sizeof</span>(server_addr));</div>
<div class="line"><span class="lineno"> 101</span> server_addr.sin_family = AF_INET;</div>
<div class="line"><span class="lineno"> 102</span> server_addr.sin_port = htons(<a class="code hl_define" href="../../da/d07/tcp__half__duplex__client_8c.html#a614217d263be1fb1a5f76e2ff7be19a2">PORT</a>);</div>
<div class="line"><span class="lineno"> 103</span> server_addr.sin_addr.s_addr = htonl(INADDR_ANY);</div>
<div class="line"><span class="lineno"> 104</span> </div>
<div class="line"><span class="lineno"> 105</span> printf(<span class="stringliteral">&quot;Client is running...\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 106</span><span class="comment"></span> </div>
<div class="line"><span class="lineno"> 107</span><span class="comment"> /**</span></div>
<div class="line"><span class="lineno"> 108</span><span class="comment"> * Connects the client to the server address using the socket descriptor</span></div>
<div class="line"><span class="lineno"> 109</span><span class="comment"> * This enables the two to communicate and exchange data</span></div>
<div class="line"><span class="lineno"> 110</span><span class="comment"> */</span></div>
<div class="line"><span class="lineno"> 111</span> connect(sockfd, (<span class="keyword">struct</span> sockaddr *)&amp;server_addr, <span class="keyword">sizeof</span>(server_addr));</div>
<div class="line"><span class="lineno"> 112</span> </div>
<div class="line"><span class="lineno"> 113</span> printf(<span class="stringliteral">&quot;Client is connected...\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 114</span><span class="comment"></span> </div>
<div class="line"><span class="lineno"> 115</span><span class="comment"> /**</span></div>
<div class="line"><span class="lineno"> 116</span><span class="comment"> * Communication between client and server</span></div>
<div class="line"><span class="lineno"> 117</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 118</span><span class="comment"> * The bzero() function erases the data in the n bytes of the memory</span></div>
<div class="line"><span class="lineno"> 119</span><span class="comment"> * starting at the location pointed to, by writing zeros (bytes</span></div>
<div class="line"><span class="lineno"> 120</span><span class="comment"> * containing &#39;\0&#39;) to that area. The variables are emptied and then</span></div>
<div class="line"><span class="lineno"> 121</span><span class="comment"> * ready for use</span></div>
<div class="line"><span class="lineno"> 122</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 123</span><span class="comment"> * First the CLIENT receives the servers message and displays it (recv())</span></div>
<div class="line"><span class="lineno"> 124</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 125</span><span class="comment"> * The CLIENT is then prompted to type in a message and send it to the</span></div>
<div class="line"><span class="lineno"> 126</span><span class="comment"> * server. (send())</span></div>
<div class="line"><span class="lineno"> 127</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 128</span><span class="comment"> * The server and client can communicate till one of them exits the</span></div>
<div class="line"><span class="lineno"> 129</span><span class="comment"> * connection</span></div>
<div class="line"><span class="lineno"> 130</span><span class="comment"> *</span></div>
<div class="line"><span class="lineno"> 131</span><span class="comment"> * Since the exchange of information between the server and client take</span></div>
<div class="line"><span class="lineno"> 132</span><span class="comment"> * place one at a time this represents HALF DUPLEX COMMUNICATION</span></div>
<div class="line"><span class="lineno"> 133</span><span class="comment"> */</span></div>
<div class="line"><span class="lineno"> 134</span> <span class="keywordflow">while</span> (1)</div>
<div class="line"><span class="lineno"> 135</span> {</div>
<div class="line"><span class="lineno"> 136</span> bzero(&amp;serverResponse, <span class="keyword">sizeof</span>(serverResponse));</div>
<div class="line"><span class="lineno"> 137</span> bzero(&amp;clientResponse, <span class="keyword">sizeof</span>(clientResponse));</div>
<div class="line"><span class="lineno"> 138</span><span class="comment"></span> </div>
<div class="line"><span class="lineno"> 139</span><span class="comment"> /// Receive Message</span></div>
<div class="line"><span class="lineno"> 140</span><span class="comment"></span> recv(sockfd, serverResponse, <span class="keyword">sizeof</span>(serverResponse), 0);</div>
<div class="line"><span class="lineno"> 141</span> printf(<span class="stringliteral">&quot;\nServer message: %s \n&quot;</span>, serverResponse);</div>
<div class="line"><span class="lineno"> 142</span><span class="comment"></span> </div>
<div class="line"><span class="lineno"> 143</span><span class="comment"> /// Send Message</span></div>
<div class="line"><span class="lineno"> 144</span><span class="comment"></span> printf(<span class="stringliteral">&quot;\nEnter message here: &quot;</span>);</div>
<div class="line"><span class="lineno"> 145</span> fgets(clientResponse, 10000, stdin);</div>
<div class="line"><span class="lineno"> 146</span> send(sockfd, clientResponse, strlen(clientResponse) + 1, 0);</div>
<div class="line"><span class="lineno"> 147</span> }</div>
<div class="line"><span class="lineno"> 148</span><span class="comment"></span> </div>
<div class="line"><span class="lineno"> 149</span><span class="comment"> /// Close Socket</span></div>
<div class="line"><span class="lineno"> 150</span><span class="comment"></span> close(sockfd);</div>
<div class="line"><span class="lineno"> 151</span> printf(<span class="stringliteral">&quot;Client is offline...\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 152</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 153</span>}</div>
<div class="ttc" id="atcp__half__duplex__client_8c_html_a614217d263be1fb1a5f76e2ff7be19a2"><div class="ttname"><a href="../../da/d07/tcp__half__duplex__client_8c.html#a614217d263be1fb1a5f76e2ff7be19a2">PORT</a></div><div class="ttdeci">#define PORT</div><div class="ttdoc">For structures returned by the network database library - formatted internet addresses and port numbe...</div><div class="ttdef"><b>Definition:</b> tcp_half_duplex_client.c:28</div></div>
<div class="ttc" id="atcp__half__duplex__client_8c_html_a7e15c8e2885871839fc2b820dfbdb4ce"><div class="ttname"><a href="../../da/d07/tcp__half__duplex__client_8c.html#a7e15c8e2885871839fc2b820dfbdb4ce">error</a></div><div class="ttdeci">void error()</div><div class="ttdoc">Utility function used to print an error message to stderr.</div><div class="ttdef"><b>Definition:</b> tcp_half_duplex_client.c:36</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../da/d07/tcp__half__duplex__client_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="158" height="36"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_d20ad0b8de644c123692ba5582cc7a7b.html">client_server</a></li><li class="navelem"><a class="el" href="../../da/d07/tcp__half__duplex__client_8c.html">tcp_half_duplex_client.c</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.5 </li>
</ul>
</div>
</body>
</html>