Question

I am trying to write a program that sends stream packets to a certain listener (I am using my localhost) in UDP, using ACE. This is in order to test my program that receives a stream of UDP datagrams from a remote peer. So far I have managed to simulate a stream, but I don't know how to receive data using a connection of a real network.

This is a code example that sends 60 packets for the localhost, will that be enough for a sender?

int SendDatagram() 
{ 
    const char* message = "this is a message!\n"; 

    ACE_INET_Addr  sender    (27016, ACE_LOCALHOST); 
    ACE_INET_Addr  listener    (27015, ACE_LOCALHOST); 
    ACE_SOCK_DGRAM udp        (sender); 


    ssize_t sent;
    char buffer[BUFSIZ]; 
    size_t size = sizeof(buffer); 
    for (int i = 0; i < 60 ; i++)
    {
        sent = udp.send(message, ACE_OS_String::strlen(message) + 1, listener); 
        if (sent == -1) 
        { 
            ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%p\n"), ACE_TEXT("send")), -1); 
        } 
        cout << "sent:     " << sent << " bytes" << endl;
    }

    udp.close(); 

    return 0; 
} 
Was it helpful?

Solution

Check chapter 9 of the ACE Programmers Guide (see http://www.amazon.com/exec/obidos/ASIN/0201699710/theaceorb-20) for how UDP works with ACE. See ACE_wrappers/examples/APG/Misc_IPC for the code that belongs to that section.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top