Question: 10. What is the the response of this server for this client if both programs are running on the same system?<div class="hk1_style-wrap4"><div class="hk1_style-wrap3"><div class="hk1_style-wrap2"><div class="hk1_style-wrap"><div class="hk1_style"><div class="c"><ol><li class="li1"><pre class="de1"> <span class="coMULTI">/*This is server.c*/</span> </pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;stdio.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;stdlib.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;netinet/in.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/types.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/socket.h&gt;</span></pre></li><li class="li1"><pre class="de1">&nbsp;</pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> fd_server<span class="sy0">,</span> fd_client<span class="sy0">,</span> len<span class="sy0">,</span> len_client<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">struct</span> sockaddr_in add_server<span class="sy0">,</span> add_client<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">char</span> buff<span class="br0">[</span><span class="nu0">10</span><span class="br0">]</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> fd_server <span class="sy0">=</span> socket<span class="br0">(</span>AF_INET<span class="sy0">,</span>SOCK_STREAM<span class="sy0">,</span><span class="nu0">0</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span> <span class="br0">(</span>fd_server <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"fd_sock"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">exit</span><span class="br0">(</span><span class="nu0">1</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> add_server.<span class="me1">sin_family</span> <span class="sy0">=</span> AF_INET<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> add_server.<span class="me1">sin_port</span> <span class="sy0">=</span> htons<span class="br0">(</span><span class="nu0">4001</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> add_server.<span class="me1">sin_addr</span>.<span class="me1">s_addr</span> <span class="sy0">=</span> inet_addr<span class="br0">(</span><span class="st0">"127.0.0.1"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> len <span class="sy0">=</span> <span class="kw4">sizeof</span><span class="br0">(</span>add_server<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> len <span class="sy0">=</span> <span class="kw4">sizeof</span><span class="br0">(</span>add_client<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span><span class="br0">(</span> bind<span class="br0">(</span>fd_server<span class="sy0">,</span><span class="br0">(</span><span class="kw4">struct</span> sockaddr<span class="sy0">*</span><span class="br0">)</span><span class="sy0">&amp;</span>add_server<span class="sy0">,</span>len<span class="br0">)</span> <span class="sy0">!=</span> <span class="nu0">0</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"bind"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span><span class="br0">(</span>listen<span class="br0">(</span>fd_server<span class="sy0">,</span><span class="nu0">5</span><span class="br0">)</span> <span class="sy0">!=</span> <span class="nu0">0</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"listen"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> fd_client <span class="sy0">=</span> accept<span class="br0">(</span>fd_server<span class="sy0">,</span><span class="br0">(</span><span class="kw4">struct</span> sockaddr<span class="sy0">*</span><span class="br0">)</span><span class="sy0">&amp;</span>add_client<span class="sy0">,&amp;</span>len_client<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span><span class="br0">(</span>fd_client <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"accept"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> read<span class="br0">(</span>fd_client<span class="sy0">,</span>buff<span class="sy0">,</span><span class="nu0">10</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">return</span> <span class="nu0">0</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> <span class="coMULTI">/*This is the client.c*/</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;stdio.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;netinet/in.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/types.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/socket.h&gt;</span></pre></li><li class="li1"><pre class="de1">&nbsp;</pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> fd_client<span class="sy0">,</span>fd<span class="sy0">,</span> len<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">struct</span> sockaddr_in add_server<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> fd_client <span class="sy0">=</span> socket<span class="br0">(</span>AF_INET<span class="sy0">,</span>SOCK_STREAM<span class="sy0">,</span><span class="nu0">0</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span> <span class="br0">(</span>fd_client <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"fd_sock"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">exit</span><span class="br0">(</span><span class="nu0">1</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> add_server.<span class="me1">sin_family</span> <span class="sy0">=</span> AF_INET<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> add_server.<span class="me1">sin_port</span> <span class="sy0">=</span> ntohs<span class="br0">(</span><span class="nu0">4001</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> add_server.<span class="me1">sin_addr</span>.<span class="me1">s_addr</span> <span class="sy0">=</span> inet_addr<span class="br0">(</span><span class="st0">"127.0.0.1"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> len <span class="sy0">=</span> <span class="kw4">sizeof</span><span class="br0">(</span>add_server<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> fd <span class="sy0">=</span> connect<span class="br0">(</span>fd_client<span class="sy0">,</span><span class="br0">(</span><span class="kw4">struct</span> sockaddr<span class="sy0">*</span><span class="br0">)</span><span class="sy0">&amp;</span>add_server<span class="sy0">,</span>len<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span><span class="br0">(</span>fd <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"connect"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> write<span class="br0">(</span>fd<span class="sy0">,</span><span class="st0">"Hello<span class="es1">\n</span>"</span><span class="sy0">,</span><span class="nu0">6</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">return</span> <span class="nu0">0</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li></ol></div></div></div></div></div></div>
Options:
the server will write back to the client whatever the clinet will write to the server
the client server communication will not work
the response can not be determined
none of the mentioned
Answer: A