Async  0.18.0
Public Member Functions | Public Attributes | List of all members
Async::UdpSocket Class Reference

A class for working with UDP sockets. More...

#include <AsyncUdpSocket.h>

Inheritance diagram for Async::UdpSocket:

Public Member Functions

 UdpSocket (uint16_t local_port=0)
 Constructor. More...
 
 ~UdpSocket (void)
 Destructor. More...
 
bool initOk (void) const
 Check if the initialization was ok. More...
 
bool write (const IpAddress &remote_ip, int remote_port, const void *buf, int count)
 Write data to the remote host. More...
 

Public Attributes

SigC::Signal3< void, const
IpAddress &, void *, int > 
dataReceived
 A signal that is emitted when data has been received. More...
 
SigC::Signal1< void, bool > sendBufferFull
 A signal that is emitted when the send buffer is full. More...
 

Detailed Description

A class for working with UDP sockets.

Author
Tobias Blomberg
Date
2003-04-26

This class is used to work with UDP sockets. An example usage is shown below.

#include <iostream>
#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);
}
};
int main(int argc, char **argv)
{
MyClass my_class;
app.exec();
}
Examples:
AsyncUdpSocket_demo.cpp.

Definition at line 124 of file AsyncUdpSocket.h.

Constructor & Destructor Documentation

Async::UdpSocket::UdpSocket ( uint16_t  local_port = 0)

Constructor.

Parameters
local_portThe local port to use. If not specified, a random local port will be used.
Async::UdpSocket::~UdpSocket ( void  )

Destructor.

Member Function Documentation

bool Async::UdpSocket::initOk ( void  ) const
inline

Check if the initialization was ok.

Returns
Returns true if everything went fine during initialization or false if something went wrong

This function should always be called after constructing the object to see if everything went fine.

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.

Parameters
remote_ipThe IP-address of the remote host
remote_portThe remote port to use
bufA buffer containing the data to send
countThe number of bytes to write
Returns
Return true on success or false on failure

Member Data Documentation

SigC::Signal3<void, const IpAddress&, void *, int> Async::UdpSocket::dataReceived

A signal that is emitted when data has been received.

Parameters
ipThe IP-address the data was received from
bufThe buffer containing the read data
countThe 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.

Parameters
is_fullSet 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.


The documentation for this class was generated from the following file: