00001 #include <iostream>
00002 #include <AsyncCppApplication.h>
00003 #include <AsyncUdpSocket.h>
00004 #include <AsyncIpAddress.h>
00005
00006 using namespace std;
00007 using namespace Async;
00008
00009 class MyClass : public sigc::trackable
00010 {
00011 public:
00012 MyClass(void)
00013 {
00014 sock = new UdpSocket(12345);
00015 sock->dataReceived.connect(mem_fun(*this, &MyClass::onDataReceived));
00016 IpAddress addr("127.0.0.1");
00017 sock->write(addr, 12345, "Hello, UDP!\n", 13);
00018 }
00019
00020 ~MyClass(void)
00021 {
00022 delete sock;
00023 }
00024
00025 private:
00026 UdpSocket * sock;
00027
00028 void onDataReceived(const IpAddress& addr, void *buf, int count)
00029 {
00030 cout << "Data received from " << addr << ": " << static_cast<char *>(buf);
00031 Application::app().quit();
00032 }
00033 };
00034
00035 int main(int argc, char **argv)
00036 {
00037 CppApplication app;
00038 MyClass my_class;
00039 app.exec();
00040 }