inbaly inbaly - 1 year ago 72
C++ Question

c++ how do I receive stream packets from internet site to my localhost

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)
cout << "sent: " << sent << " bytes" << endl;


return 0;

Answer Source

Check chapter 9 of the ACE Programmers Guide (see for how UDP works with ACE. See ACE_wrappers/examples/APG/Misc_IPC for the code that belongs to that section.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download