File: tcpstr1.cpp

package info (click to toggle)
libcommoncpp2 1.8.1-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,300 kB
  • sloc: cpp: 29,221; sh: 10,352; ansic: 1,134; makefile: 238; xml: 5
file content (42 lines) | stat: -rw-r--r-- 677 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <cc++/socket.h>
#include <iostream>
#include <cstdlib>

#ifdef	CCXX_NAMESPACES
using namespace std;
using namespace ost;
#endif

class ThreadOut: public Thread
{
public:
	ThreadOut() {
		start();
	}
	void run() {
		TCPStream tcp("127.0.0.1:9000");
		tcp << "pippo" << endl;
		tcp.disconnect();
	}
};

int main(int argc, char *argv[])
{
	char line[200];

	InetAddress addr = "127.0.0.1";
	TCPSocket *sock = new TCPSocket(addr, 9000);
	// write some output automatically
	ThreadOut thread;
	while (1){
		if (sock->isPendingConnection()){
			TCPStream tcp(*sock);
			tcp.getline(line, 200);
			cout << line << endl;
			tcp.disconnect();
			return 0;
		}
	}
	return 0;
}