<!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: AsyncUdpSocket_demo.cpp</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 Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><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> <div class="contents"> <h1>AsyncUdpSocket_demo.cpp</h1><p>An example of how to use the <a class="el" href="classAsync_1_1UdpSocket.html" title="A class for working with UDP sockets.">Async::UdpSocket</a> class</p> <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <iostream></span> <span class="preprocessor">#include <<a class="code" href="AsyncCppApplication_8h.html" title="The core class for writing asyncronous cpp applications.">AsyncCppApplication.h</a>></span> <span class="preprocessor">#include <<a class="code" href="AsyncUdpSocket_8h.html" title="Contains a class for using UDP sockets.">AsyncUdpSocket.h</a>></span> <span class="preprocessor">#include <<a class="code" href="AsyncIpAddress_8h.html" title="Platform independent representation of an IP address.">AsyncIpAddress.h</a>></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>) { sock = <span class="keyword">new</span> <a name="_a0"></a><a class="code" href="classAsync_1_1UdpSocket.html" title="A class for working with UDP sockets.">UdpSocket</a>(12345); sock->dataReceived.connect(slot(*<span class="keyword">this</span>, &MyClass::onDataReceived)); <a name="_a1"></a><a class="code" href="classAsync_1_1IpAddress.html" title="A class for representing an IP address in an OS independent way.">IpAddress</a> addr(<span class="stringliteral">"127.0.0.1"</span>); sock->write(addr, 12345, <span class="stringliteral">"Hello, UDP!\n"</span>, 13); } ~MyClass(<span class="keywordtype">void</span>) { <span class="keyword">delete</span> sock; } <span class="keyword">private</span>: <a class="code" href="classAsync_1_1UdpSocket.html" title="A class for working with UDP sockets.">UdpSocket</a> * sock; <span class="keywordtype">void</span> onDataReceived(<span class="keyword">const</span> <a class="code" href="classAsync_1_1IpAddress.html" title="A class for representing an IP address in an OS independent way.">IpAddress</a>& addr, <span class="keywordtype">void</span> *buf, <span class="keywordtype">int</span> count) { cout << <span class="stringliteral">"Data received from "</span> << addr << <span class="stringliteral">": "</span> << <span class="keyword">static_cast<</span><span class="keywordtype">char</span> *<span class="keyword">></span>(buf); Application::app().quit(); } }; <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) { <a name="_a2"></a><a class="code" href="classAsync_1_1CppApplication.html" title="An application class for writing non GUI applications.">CppApplication</a> app; MyClass my_class; app.<a name="a3"></a><a class="code" href="classAsync_1_1CppApplication.html#a9a921d33644bbb18767fb4d599f53bf4" title="Execute the application main loop.">exec</a>(); } </pre></div> </div> <hr class="footer"/><address style="text-align: right;"><small>Generated by <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>