Async 1.8.0
AsyncUdpSocket_demo.cpp

An example of how to use the Async::UdpSocket class

#include <iostream>
#include <AsyncUdpSocket.h>
#include <AsyncIpAddress.h>
using namespace std;
using namespace Async;
class MyClass : public sigc::trackable
{
public:
MyClass(void)
{
sock = new UdpSocket(12345);
sock->dataReceived.connect(mem_fun(*this, &MyClass::onDataReceived));
IpAddress addr("127.0.0.1");
sock->write(addr, 12345, "Hello, UDP!\n", 13);
}
~MyClass(void)
{
delete sock;
}
private:
UdpSocket * sock;
void onDataReceived(const IpAddress& addr, uint16_t port,
void *buf, int count)
{
cout << "Data received from " << addr << ":" << port << ": "
<< static_cast<char *>(buf);
Application::app().quit();
}
};
int main(int argc, char **argv)
{
MyClass my_class;
app.exec();
}
The core class for writing asyncronous cpp applications.
Platform independent representation of an IP address.
Contains a class for using UDP sockets.
An application class for writing non GUI applications.
void exec(void)
Execute the application main loop.
A class for representing an IP address in an OS independent way.
A class for working with UDP sockets.
Namespace for the asynchronous programming classes.