#include <cstdio>
#include <cstdlib>
#ifdef CCXX_NAMESPACES
using namespace ost;
using namespace std;
#endif
class ccRTP_dupHello: public Thread
{
private:
public:
~ccRTP_dupHello()
{
terminate();
delete duplexA;
delete duplexB;
}
ccRTP_dupHello() : duplexA(NULL), duplexB(NULL)
{}
void run(void)
{
InetHostAddress local_ip;
local_ip = "127.0.0.1";
if( ! local_ip ) {
cerr << ": IP address is not correct!" << endl;
exit();
}
cout << local_ip.getHostname() <<
" is going to talk to perself through " <<
local_ip << "..." << endl;
const int A_BASE = 22222;
const int B_BASE = 33334;
duplexA =
new RTPDuplex(local_ip,A_BASE,B_BASE);
duplexB =
new RTPDuplex(local_ip,B_BASE,A_BASE);
if( duplexA->
connect(local_ip,B_BASE) < 0 )
cerr << "Duplex A could not connect.";
if( duplexB->
connect(local_ip,A_BASE) < 0 )
cerr << "Duplex B could not connect.";
if( duplexA->RTPDataQueue::isActive() )
cout << "The queue A is active." << endl;
else
cerr << "The queue A is not active." << endl;
if( duplexB->RTPDataQueue::isActive() )
cout << "The queue B is active." << endl;
else
cerr << "The queue B is not active." << endl;
cout << "Transmitting..." << endl;
unsigned char helloA[] = "Hello, brave gnu world from A!";
unsigned char helloB[] = "Hello, brave gnu world from B!";
time_t sending_time;
time_t receiving_time;
char tmstring[30];
for( int i = 0 ; true ; i++ ) {
sending_time = time(NULL);
duplexA->
putData(2*(i)*90000,helloA,
strlen((char *)helloA));
strftime(tmstring,30,"%X",localtime(&sending_time));
cout << "A: sending message at " << tmstring << "..."
<< endl;
receiving_time = time(NULL);
if ( aduA ) {
strftime(tmstring,30,"%X",localtime(&receiving_time));
cout << "A:[receiving at " << tmstring << "]: " <<
}
Thread::sleep(100);
sending_time = time(NULL);
duplexB->
putData(2*(i)*90000,helloB,
strlen((char *)helloB));
strftime(tmstring,30,"%X",localtime(&sending_time));
cout << "B: sending message at " << tmstring << "..."
<< endl;
receiving_time = time(NULL);
if ( aduB ) {
strftime(tmstring,30,"%X",localtime(&receiving_time));
cout << "B:[receiving at " << tmstring << "]: " <<
}
Thread::sleep(1900);
}
}
};
int main(int argc, char *argv[])
{
ccRTP_dupHello *hello = new ccRTP_dupHello;
cout << "This is rtpduphello, a very simple test program for ccRTP."
<< endl << "Strike [Enter] when you are fed up." << endl;
hello->start();
cin.get();
cout << endl << "That's all" << endl;
delete hello;
exit(0);
}