<!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>GNU CommonC++: tcpstr1.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.3 --> <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="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div class="contents"> <h1>tcpstr1.cpp</h1><div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="socket_8h.html" title="Network addresses and sockets related classes.">cc++/socket.h</a>></span> <span class="preprocessor">#include <iostream></span> <span class="preprocessor">#include <cstdlib></span> <span class="preprocessor">#ifdef CCXX_NAMESPACES</span> <span class="preprocessor"></span><span class="keyword">using namespace </span>std; <span class="keyword">using namespace </span>ost; <span class="preprocessor">#endif</span> <span class="preprocessor"></span> <span class="keyword">class </span>ThreadOut: <span class="keyword">public</span> <a name="_a0"></a><a class="code" href="classost_1_1_thread.html" title="Every thread of execution in an application is created by instantiating an object...">Thread</a> { <span class="keyword">public</span>: ThreadOut() { <a name="a1"></a><a class="code" href="classost_1_1_thread.html#a2ef198d7aefb93cf9de4fcc6b66c27a2" title="When a new thread is created, it does not begin immediate execution.">start</a>(); } <span class="keywordtype">void</span> <a name="a2"></a><a class="code" href="classost_1_1_thread.html#add7d339d94b8a1ed2b2b0324a95b7e74" title="All threads execute by deriving the Run method of Thread.">run</a>() { <a name="_a3"></a><a class="code" href="classost_1_1_t_c_p_stream.html" title="TCP streams are used to represent TCP client connections to a server by TCP protocol...">TCPStream</a> tcp(<span class="stringliteral">"127.0.0.1:9000"</span>); tcp << <span class="stringliteral">"pippo"</span> << endl; tcp.<a name="a4"></a><a class="code" href="classost_1_1_t_c_p_stream.html#a465c1772f8b6c1e1effcdfdc248622af" title="Disconnect the current session and prepare for a new one.">disconnect</a>(); } }; <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) { <span class="keywordtype">char</span> line[200]; <a name="a5"></a><a class="code" href="address_8h.html#a029ebb5b43bb13b02c02f4de0a8f3c08">InetAddress</a> addr = <span class="stringliteral">"127.0.0.1"</span>; <a name="_a6"></a><a class="code" href="classost_1_1_t_c_p_socket.html" title="TCP sockets are used for stream based connected sessions between two sockets.">TCPSocket</a> *sock = <span class="keyword">new</span> <a class="code" href="classost_1_1_t_c_p_socket.html" title="TCP sockets are used for stream based connected sessions between two sockets.">TCPSocket</a>(addr, 9000); <span class="comment">// write some output automatically</span> ThreadOut thread; <span class="keywordflow">while</span> (1){ <span class="keywordflow">if</span> (sock-><a name="a7"></a><a class="code" href="classost_1_1_t_c_p_socket.html#a112e8235b317f15e15f6ea264fe81eb7" title="Used to wait for pending connection requests.">isPendingConnection</a>()){ <a class="code" href="classost_1_1_t_c_p_stream.html" title="TCP streams are used to represent TCP client connections to a server by TCP protocol...">TCPStream</a> tcp(*sock); tcp.getline(line, 200); cout << line << endl; tcp.disconnect(); <span class="keywordflow">return</span> 0; } } <span class="keywordflow">return</span> 0; } </pre></div> </div> <hr class="footer"/><address style="text-align: right;"><small>Generated on Fri Nov 12 09:55:46 2010 for GNU CommonC++ by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address> </body> </html>