#include <AsyncUdpSocket.h>
#include <iostream> #include <AsyncCppApplication.h> #include <AsyncUdpSocket.h> #include <AsyncIpAddress.h> using namespace std; using namespace Async; class MyClass : public SigC::Object { public: MyClass(void) { sock = new UdpSocket(12345); sock->dataReceived.connect(slot(*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, void *buf, int count) { cout << "Data received from " << addr << ": " << static_cast<char *>(buf); Application::app().quit(); } }; int main(int argc, char **argv) { CppApplication app; MyClass my_class; app.exec(); }
Definition at line 124 of file AsyncUdpSocket.h.
Async::UdpSocket::UdpSocket | ( | uint16_t | local_port = 0 |
) |
Constructor.
local_port | The local port to use. If not specified, a random local port will be used. |
Async::UdpSocket::~UdpSocket | ( | void | ) |
Destructor.
bool Async::UdpSocket::initOk | ( | void | ) | const [inline] |
Check if the initialization was ok.
Definition at line 147 of file AsyncUdpSocket.h.
bool Async::UdpSocket::write | ( | const IpAddress & | remote_ip, | |
int | remote_port, | |||
const void * | buf, | |||
int | count | |||
) |
Write data to the remote host.
remote_ip | The IP-address of the remote host | |
remote_port | The remote port to use | |
buf | A buffer containing the data to send | |
count | The number of bytes to write |
SigC::Signal3<void, const IpAddress&, void *, int> Async::UdpSocket::dataReceived |
A signal that is emitted when data has been received.
ip | The IP-address the data was received from | |
buf | The buffer containing the read data | |
count | The number of bytes read |
Definition at line 166 of file AsyncUdpSocket.h.
SigC::Signal1<void, bool> Async::UdpSocket::sendBufferFull |
A signal that is emitted when the send buffer is full.
is_full | Set to true if the buffer is full or false if the buffer full condition has been cleared |
Definition at line 173 of file AsyncUdpSocket.h.