#include <cstdio>
#include <ctime>
#ifdef CCXX_NAMESPACES
using namespace ost;
using namespace std;
#endif
const int RECEIVER_BASE = 33634;
const int TRANSMITTER_BASE = 32522;
class ccRTP_Hello_Rx: public Thread
{
private:
InetHostAddress local_ip;
uint32 ssrc;
public:
ccRTP_Hello_Rx(){
local_ip = "127.0.0.1";
if( ! local_ip ){
cerr << "Rx: IP address is not correct!" << endl;
exit();
}
}
~ccRTP_Hello_Rx(){
cout << endl << "Destroying receiver -ID: " << hex
<< (int)ssrc;
terminate();
delete socket;
cout << "... " << "destroyed.";
}
void run(void){
<< " ..." << endl;
cerr << "Rx (" << hex << (int)ssrc
<< "): could not connect to port."
<< TRANSMITTER_BASE;
cout << "Rx (" << hex << (int)ssrc
<< "): " << local_ip.getHostname()
<< " is waiting for salutes in port "
<< RECEIVER_BASE << "..." << endl;
cout << "Rx (" << hex << (int)ssrc
<< "): The queue is "
<< "active." << endl;
for( int i = 0 ; true ; i++ ){
while ( NULL == adu ) {
Thread::sleep(10);
}
time_t receiving_time = time(NULL);
char tmstring[30];
strftime(tmstring,30,"%X",localtime(&receiving_time));
cout << "Rx (" << hex << (int)ssrc
<< "): [receiving at " << tmstring << "]: "
delete adu;
}
}
};
class ccRTP_Hello_Tx: public Thread, public TimerPort
{
private:
InetHostAddress local_ip;
uint32 ssrc;
public:
ccRTP_Hello_Tx(){
local_ip = "127.0.0.1";
if( ! local_ip ){
cerr << "Tx: IP address is not correct!" << endl;
exit();
}
socket =
new RTPSession(local_ip,TRANSMITTER_BASE);
}
~ccRTP_Hello_Tx(){
cout << endl << "Destroying transmitter -ID: " << hex
<< (int)ssrc;
terminate();
delete socket;
cout << "... " << "destroyed.";
}
void run(void){
cout << "Tx (" << hex << (int)ssrc << "): " <<
local_ip.getHostname()
<< " is going to salute perself through "
<< local_ip << "..." << endl;
cerr << "Tx (" << hex << (int)ssrc
<< "): could not connect to port."
<< RECEIVER_BASE;
cout << "Tx (" << hex << (int)ssrc <<
"): Transmitting salutes to port "
<< RECEIVER_BASE << "..." << endl;
uint32 timestamp = 0;
TimerPort::setTimer(1000);
cout << "Tx (" << hex << (int)ssrc << "): The queue is "
<< "active." << endl;
for( int i = 0 ; true ;i++ ){
unsigned char salute[50];
snprintf((char *)salute,50,
"Hello, brave gnu world (#%u)!",i);
time_t sending_time = time(NULL);
if ( 0 == i ){
} else {
}
strlen((char *)salute)+1);
char tmstring[30];
strftime(tmstring,30,"%X",
localtime(&sending_time));
cout << "Tx (" << hex << (int)ssrc
<< "): sending salute " << "no " << dec << i
<< ", at " << tmstring
<< "..." << endl;
Thread::sleep(TimerPort::getTimer());
TimerPort::incTimer(1000);
}
}
};
int main(int argc, char *argv[])
{
ccRTP_Hello_Rx *receiver = new ccRTP_Hello_Rx;
ccRTP_Hello_Tx *transmitter = new ccRTP_Hello_Tx;
cout << "This is rtphello, a very simple test program for ccRTP." <<
endl << "Strike [Enter] when you are fed up with it." << endl;
receiver->start();
transmitter->start();
cin.get();
delete transmitter;
delete receiver;
cout << endl << "That's all." << endl;
return 0;
}