0

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; 
} 
inbaly
  • 582
  • 1
  • 6
  • 16
  • 2
    "UDP" and "stream" in the same sequence? Are you trying to spell "TCP"? – Remus Rusanu Jan 06 '14 at 12:08
  • Where is sent declared? Why are you receiving packets and then checking sent instead of received - is this your real code? Anyway, did you actually test your code with a remote peer, and the peer addresses instead of `ACE_LOCALHOST`? – Useless Jan 06 '14 at 13:33
  • I meant UDP. My program receives a stream of UDP datagrams. You are right - the code should be "send", bad copy paste... – inbaly Jan 06 '14 at 13:41
  • Can you make your question more specific? And put a question mark after it? ;-) All I can gleam from your post is "how do I write software, using ACE, that receives data from the network?", which has a very non-trivial answer. – Aaron Jan 06 '14 at 19:19

1 Answers1

0

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.

Johnny Willemsen
  • 2,942
  • 1
  • 14
  • 16
  • I have found a good link that helped me find a solution: http://code.msdn.microsoft.com/windowsdesktop/Sockets-with-Adaptive-c9f5cc2b – inbaly Feb 01 '14 at 09:35