Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > os > by-pkgid > 9c481c872fb0ae0cbadccdc2f4a18ab6 > files > 226

libasync-devel-0.17.0-5.fc14.x86_64.rpm

<!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"/>
<title>Async: Async::TcpClient Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2-20100208 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="namespaceAsync.html">Async</a>::<a class="el" href="classAsync_1_1TcpClient.html">TcpClient</a>
  </div>
</div>
<div class="contents">
<h1>Async::TcpClient Class Reference</h1><!-- doxytag: class="Async::TcpClient" --><!-- doxytag: inherits="Async::TcpConnection" -->
<p>A class for creating a TCP client connection.  
<a href="#_details">More...</a></p>

<p><code>#include &lt;<a class="el" href="AsyncTcpClient_8h_source.html">AsyncTcpClient.h</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for Async::TcpClient:</div>
<div class="dynsection">
 <div class="center">
  <img src="classAsync_1_1TcpClient.png" usemap="#Async::TcpClient_map" alt=""/>
  <map id="Async::TcpClient_map" name="Async::TcpClient_map">
<area href="classAsync_1_1TcpConnection.html" alt="Async::TcpConnection" shape="rect" coords="0,0,139,24"/>
</map>
 </div>
</div>

<p><a href="classAsync_1_1TcpClient-members.html">List of all members.</a></p>
<h2>Public Member Functions</h2>
<ul>
<li><a class="el" href="classAsync_1_1TcpClient.html#a1fe65f4181355e2e68fc636d47e3e2fa">TcpClient</a> (const std::string &amp;remote_host, uint16_t remote_port, size_t recv_buf_len=<a class="el" href="classAsync_1_1TcpConnection.html#a27f6e87af1a6d57eb4e3eed7a9f73a7b">DEFAULT_RECV_BUF_LEN</a>)
<dl class="el"><dd class="mdescRight">Constructor.  <a href="#a1fe65f4181355e2e68fc636d47e3e2fa"></a><br/></dl><li><a class="el" href="classAsync_1_1TcpClient.html#ae5b41aa012bcdf052c955dccc350a85f">~TcpClient</a> (void)
<dl class="el"><dd class="mdescRight">Destructor.  <a href="#ae5b41aa012bcdf052c955dccc350a85f"></a><br/></dl><li>void <a class="el" href="classAsync_1_1TcpClient.html#a0136bf428c3ffe9abbe66dc9a9349178">connect</a> (void)
<dl class="el"><dd class="mdescRight">Connect to the remote host.  <a href="#a0136bf428c3ffe9abbe66dc9a9349178"></a><br/></dl><li>void <a class="el" href="classAsync_1_1TcpClient.html#a673550120d3693131897629030e4ee97">disconnect</a> (void)
<dl class="el"><dd class="mdescRight">Disconnect from the remote host.  <a href="#a673550120d3693131897629030e4ee97"></a><br/></dl></ul>
<h2>Public Attributes</h2>
<ul>
<li>SigC::Signal0&lt; void &gt; <a class="el" href="classAsync_1_1TcpClient.html#a2b145b50eb62c7871ce4c30a190b0de1">connected</a>
<dl class="el"><dd class="mdescRight">A signal that is emitted when a connection has been established.  <a href="#a2b145b50eb62c7871ce4c30a190b0de1"></a><br/></dl></ul>
<hr/><a name="_details"></a><h2>Detailed Description</h2>
<p>A class for creating a TCP client connection. </p>
<dl class="author"><dt><b>Author:</b></dt><dd>Tobias Blomberg </dd></dl>
<dl class="date"><dt><b>Date:</b></dt><dd>2003-04-12</dd></dl>
<p>This class is used to create a TCP client connection. All details of how to create the connection is hidden inside the class. This make it very easy to create and use the connections. An example usage is shown below.</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;iostream&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="AsyncCppApplication_8h.html" title="The core class for writing asyncronous cpp applications.">AsyncCppApplication.h</a>&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="AsyncTcpClient_8h.html" title="Contains a class for creating TCP client connections.">AsyncTcpClient.h</a>&gt;</span>

<span class="keyword">using namespace </span>std;
<span class="keyword">using namespace </span>Async;

<span class="keyword">class </span>MyClass : <span class="keyword">public</span> SigC::Object
{
  <span class="keyword">public</span>:
    MyClass(<span class="keywordtype">void</span>)
    {
      con = <span class="keyword">new</span> <a class="code" href="classAsync_1_1TcpClient.html#a1fe65f4181355e2e68fc636d47e3e2fa" title="Constructor.">TcpClient</a>(<span class="stringliteral">&quot;www.linux.org&quot;</span>, 80);
      con-&gt;connected.connect(slot(*<span class="keyword">this</span>, &amp;MyClass::onConnected));
      con-&gt;disconnected.connect(slot(*<span class="keyword">this</span>, &amp;MyClass::onDisconnected));
      con-&gt;dataReceived.connect(slot(*<span class="keyword">this</span>, &amp;MyClass::onDataReceived));
      con-&gt;connect();
    }
    
    ~MyClass(<span class="keywordtype">void</span>)
    {
      <span class="keyword">delete</span> con;
    }

  <span class="keyword">private</span>:
    <a class="code" href="classAsync_1_1TcpClient.html#a1fe65f4181355e2e68fc636d47e3e2fa" title="Constructor.">TcpClient</a> *con;
    
    <span class="keywordtype">void</span> onConnected(<span class="keywordtype">void</span>)
    {
      cout &lt;&lt; <span class="stringliteral">&quot;Connection established to &quot;</span> &lt;&lt; con-&gt;remoteHost() &lt;&lt; <span class="stringliteral">&quot;...\n&quot;</span>;
      con-&gt;write(<span class="stringliteral">&quot;GET /\n&quot;</span>, 6);
    }
    
    <span class="keywordtype">void</span> onDisconnected(<a class="code" href="classAsync_1_1TcpConnection.html#ae638911f865af2d2ba71a02a5009c6da" title="Constructor.">TcpConnection</a> *con, <a class="code" href="classAsync_1_1TcpConnection.html#a2a09caf85797c567d0cfce6f29ab9dd4" title="Reason code for disconnects.">TcpClient::DisconnectReason</a> reason)
    {
      cout &lt;&lt; <span class="stringliteral">&quot;Disconnected from &quot;</span> &lt;&lt; con-&gt;remoteHost() &lt;&lt; <span class="stringliteral">&quot;...\n&quot;</span>;
      <a class="code" href="classAsync_1_1Application.html#aa6d446d6b333e0a1e5cc1400c07aa898" title="Get the one and only application instance.">Application::app</a>().quit();
    }
    
    <span class="keywordtype">int</span> onDataReceived(<a class="code" href="classAsync_1_1TcpConnection.html#ae638911f865af2d2ba71a02a5009c6da" title="Constructor.">TcpConnection</a> *con, <span class="keywordtype">void</span> *buf, <span class="keywordtype">int</span> count)
    {
      <span class="keywordtype">char</span> *str = <span class="keyword">static_cast&lt;</span><span class="keywordtype">char</span> *<span class="keyword">&gt;</span>(buf);
      <span class="keywordtype">string</span> html(str, str+count);
      cout &lt;&lt; html;
      <span class="keywordflow">return</span> count;
    }
};

<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
  CppApplication app;
  MyClass my_class;
  app.exec();
}
</pre></div> <dl><dt><b>Examples: </b></dt><dd>
<p><a class="el" href="AsyncTcpClient__demo_8cpp-example.html#_a0">AsyncTcpClient_demo.cpp</a>.</p>
</dd>
</dl>
<p>Definition at line <a class="el" href="AsyncTcpClient_8h_source.html#l00130">130</a> of file <a class="el" href="AsyncTcpClient_8h_source.html">AsyncTcpClient.h</a>.</p>
<hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="a1fe65f4181355e2e68fc636d47e3e2fa"></a><!-- doxytag: member="Async::TcpClient::TcpClient" ref="a1fe65f4181355e2e68fc636d47e3e2fa" args="(const std::string &amp;remote_host, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Async::TcpClient::TcpClient </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>remote_host</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint16_t&nbsp;</td>
          <td class="paramname"> <em>remote_port</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&nbsp;</td>
          <td class="paramname"> <em>recv_buf_len</em> = <code><a class="el" href="classAsync_1_1TcpConnection.html#a27f6e87af1a6d57eb4e3eed7a9f73a7b">DEFAULT_RECV_BUF_LEN</a></code></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Constructor. </p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>remote_host</em>&nbsp;</td><td>The hostname of the remote host </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>remote_port</em>&nbsp;</td><td>The port on the remote host to connect to </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>recv_buf_len</em>&nbsp;</td><td>The length of the receiver buffer to use</td></tr>
  </table>
  </dd>
</dl>
<p>The object will be constructed and variables will be initialized but no connection will be created until the connect function (see <a class="el" href="classAsync_1_1TcpClient.html#a0136bf428c3ffe9abbe66dc9a9349178">TcpClient::connect</a>) is called. </p>

</div>
</div>
<a class="anchor" id="ae5b41aa012bcdf052c955dccc350a85f"></a><!-- doxytag: member="Async::TcpClient::~TcpClient" ref="ae5b41aa012bcdf052c955dccc350a85f" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Async::TcpClient::~TcpClient </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname"></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Destructor. </p>

</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a0136bf428c3ffe9abbe66dc9a9349178"></a><!-- doxytag: member="Async::TcpClient::connect" ref="a0136bf428c3ffe9abbe66dc9a9349178" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Async::TcpClient::connect </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname"></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Connect to the remote host. </p>
<p>This function will initiate a connection to the remote host. The connection must not be written to before the connected signal (see <a class="el" href="classAsync_1_1TcpClient.html#a2b145b50eb62c7871ce4c30a190b0de1">TcpClient::connected</a>) has been emitted. If the connection is already established or pending, nothing will be done. </p>

</div>
</div>
<a class="anchor" id="a673550120d3693131897629030e4ee97"></a><!-- doxytag: member="Async::TcpClient::disconnect" ref="a673550120d3693131897629030e4ee97" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Async::TcpClient::disconnect </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname"></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Disconnect from the remote host. </p>
<p>Call this function to disconnect from the remote host. If already disconnected, nothing will be done. The disconnected signal is not emitted when this function is called </p>

<p>Reimplemented from <a class="el" href="classAsync_1_1TcpConnection.html#a31edfcb938751a142731bce63ace3412">Async::TcpConnection</a>.</p>

</div>
</div>
<hr/><h2>Member Data Documentation</h2>
<a class="anchor" id="a2b145b50eb62c7871ce4c30a190b0de1"></a><!-- doxytag: member="Async::TcpClient::connected" ref="a2b145b50eb62c7871ce4c30a190b0de1" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">SigC::Signal0&lt;void&gt; <a class="el" href="classAsync_1_1TcpClient.html#a2b145b50eb62c7871ce4c30a190b0de1">Async::TcpClient::connected</a></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>A signal that is emitted when a connection has been established. </p>

<p>Definition at line <a class="el" href="AsyncTcpClient_8h_source.html#l00173">173</a> of file <a class="el" href="AsyncTcpClient_8h_source.html">AsyncTcpClient.h</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="AsyncTcpClient_8h_source.html">AsyncTcpClient.h</a></li>
</ul>
</div>
<hr class="footer"/><address style="text-align: right;"><small>Generated by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2-20100208 </small></address>
</body>
</html>