GNU CommonC++
tcpstr1.cpp
#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;
}
#define InetAddress
Definition address.h:75
TCP sockets are used for stream based connected sessions between two sockets.
Definition socket.h:1396
bool isPendingConnection(timeout_t timeout=TIMEOUT_INF)
Used to wait for pending connection requests.
Definition socket.h:1480
TCP streams are used to represent TCP client connections to a server by TCP protocol servers for acce...
Definition socket.h:1632
void disconnect(void)
Disconnect the current session and prepare for a new one.
Every thread of execution in an application is created by instantiating an object of a class derived ...
Definition thread.h:1094
Definition address.h:64
Network addresses and sockets related classes.