client_code.html 8.24 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>Socket: Client</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="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</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 style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Socket
   </div>
   <div id="projectbrief">Librería para comunicar via TCP/IP</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generado por Doxygen 1.8.3.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Buscar');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Página&#160;principal</span></a></li>
      <li class="current"><a href="pages.html"><span>Páginas&#160;relacionadas</span></a></li>
      <li><a href="annotated.html"><span>Clases</span></a></li>
      <li><a href="files.html"><span>Archivos</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Buscar" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>Todo</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Clases</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Archivos</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Funciones</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>&apos;defines&apos;</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Páginas</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Client </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Ejemplo de aplicación cliente</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="_socket_8h.html" title="Header de la clase Socket.">Socket.h</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="_socket_exception_8h.html" title="Header de excepción de Sockets.">SocketException.h</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &lt;sstream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;signal.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cstdlib&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;sys/time.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>std;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> <a class="code" href="client_8cpp.html#a00a6f7afcba6bb656a7b05c67efa42ba" title="Método para terminar el cliente.">exitClient</a>(<span class="keywordtype">int</span> signal)</div>
<div class="line">{</div>
<div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Server connection terminated unexpectedly&quot;</span> &lt;&lt; endl &lt;&lt; <span class="stringliteral">&quot;Exiting&quot;</span> &lt;&lt; endl;</div>
<div class="line">        exit(-1);</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> <a class="code" href="client_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4" title="Método principal del cliente.">main</a>()</div>
<div class="line">{</div>
<div class="line">        signal(SIGPIPE, <a class="code" href="client_8cpp.html#a00a6f7afcba6bb656a7b05c67efa42ba" title="Método para terminar el cliente.">exitClient</a>);</div>
<div class="line">        signal(SIGINT, <a class="code" href="client_8cpp.html#a00a6f7afcba6bb656a7b05c67efa42ba" title="Método para terminar el cliente.">exitClient</a>);</div>
<div class="line">        <a class="code" href="class_socket.html" title="Clase del socket.">Socket</a> s;</div>
<div class="line">        <span class="keywordtype">string</span> send, recv, host;</div>
<div class="line">        <span class="keywordtype">int</span> port;</div>
<div class="line">        s.<a class="code" href="class_socket.html#add736ccf41f102910a2b8ac5e77eb8b1" title="Método para crear sockets.">Create</a>();</div>
<div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Created socket&quot;</span> &lt;&lt; endl;</div>
<div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Hostname: &quot;</span>;</div>
<div class="line">        cin &gt;&gt; host;</div>
<div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Port: &quot;</span>;</div>
<div class="line">        cin &gt;&gt; port;</div>
<div class="line">        cin.ignore();</div>
<div class="line">        s.<a class="code" href="class_socket.html#aa1d074c1aa400e8bca7c7da79b036abe" title="Método para efectuar conexiones.">Connect</a>(host,port);</div>
<div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Connected&quot;</span> &lt;&lt; endl;</div>
<div class="line">        <span class="keywordflow">while</span>(<span class="keyword">true</span>)</div>
<div class="line">        {</div>
<div class="line">                cout &lt;&lt; <span class="stringliteral">&quot;&gt; &quot;</span>;</div>
<div class="line">                getline(cin,send);</div>
<div class="line">                s &gt;&gt; recv;</div>
<div class="line">                cout &lt;&lt; <span class="stringliteral">&quot;Received: &quot;</span> &lt;&lt; recv &lt;&lt; endl;</div>
<div class="line">        }</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generado el Sábado, 7 de Diciembre de 2013 01:45:57 para Socket por &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.3.1
</small></address>
</body>
</html>