Sophie

Sophie

distrib > Mandriva > 2007.0 > i586 > by-pkgid > ad1ba1135a9c9eeffc2e538163e00373 > files > 881

libCommonC++2_1.4-devel-1.4.1-1mdv2007.0.i586.rpm

\section{tcpstr1.cpp}


\footnotesize\begin{verbatim}1 #include <cc++/socket.h>
2 #include <iostream>
3 #include <cstdlib>
4 
5 #ifdef  CCXX_NAMESPACES
6 using namespace std;
7 using namespace ost;
8 #endif
9 
10 class ThreadOut: public Thread
11 {
12 public:
13         ThreadOut()
14         {
15                 start();
16         }
17         void run()
18         {
19                 TCPStream tcp("127.0.0.1:9000");
20                 tcp << "pippo" << endl;
21                 tcp.disconnect();
22         }
23 };
24 
25 int main(int argc, char *argv[])
26 {
27         char line[200];
28 
29         InetAddress addr = "127.0.0.1";
30         TCPSocket *sock = new TCPSocket(addr, 9000);
31         // write some output automatically
32         ThreadOut thread;
33         while (1){
34                 if (sock->isPendingConnection()){
35                         TCPStream tcp(*sock);
36                         tcp.getline(line, 200);
37                         cout << line << endl;
38                         tcp.disconnect();
39                         return 0;
40                 }
41         }
42         return 0;
43 }
44 
\end{verbatim}
\normalsize