OpenDaVINCI  4.16.0
odcore::io::udp::UDPReceiver Class Referenceabstract

#include <UDPReceiver.h>

Inheritance diagram for odcore::io::udp::UDPReceiver:
Inheritance graph

Public Member Functions

virtual ~UDPReceiver ()
 
virtual void start ()=0
 
virtual void stop ()=0
 
virtual void setStringListener (StringListener *sl)
 
virtual void setPacketListener (PacketListener *pl)
 
void setSynchronousPacketListener (PacketListener *pl)
 
virtual void setSenderPortToIgnore (const uint16_t &portToIgnore)=0
 

Protected Member Functions

 UDPReceiver ()
 
void nextPacket (const odcore::data::Packet &p)
 

Detailed Description

This class is the abstract superclass for receiving UDP packets using UDP.

It can be used for a stringlistener receiving asynchronously decoupled strings or for a packetlistener receiving synchronously packets.

class MyStringListener : public StringListener {
public:
virtual void nextString(const string &s) {
clog << "Received: " << s << endl;
}
};
...
MyStringListener msl;
const string address = "0.0.0.0";
const uint32_t port = 12345;
std::shared_ptr<UDPReceiver> r;
try {
r = UDPFactory::createUDPReceiver(address, port);
}
catch(string &s) {
clog << "Failed: " << s << endl;
}
if (r.isValid()) {
r->setStringListener(&msl);
r->start();
}
...
// Do some different things.
...
if (r.isValid()) {
r->stop();
}

Constructor & Destructor Documentation

odcore::io::udp::UDPReceiver::UDPReceiver ( )
protected

Protected constructor for enforcing subclasses for this class.

References odcore::base::Service::start().

odcore::io::udp::UDPReceiver::~UDPReceiver ( )
virtual

Member Function Documentation

void odcore::io::udp::UDPReceiver::nextPacket ( const odcore::data::Packet &  p)
protected

This method is called from deriving classes to pass newly arrived packets.

References odcore::io::PacketListener::nextPacket(), odcore::io::PacketPipeline::nextPacket(), and odcore::io::StringListener::nextString().

void odcore::io::udp::UDPReceiver::setPacketListener ( PacketListener pl)
virtual

This method sets or sets a packet listener.

Parameters
plPacketListener to be set. If set to NULL, observing is suspended.

Implements odcore::io::PacketObserver.

References odcore::io::PacketPipeline::setPacketListener().

virtual void odcore::io::udp::UDPReceiver::setSenderPortToIgnore ( const uint16_t &  portToIgnore)
pure virtual

This method sets the port to be ignored to receive from to avoid circular data sending and receiving from the same process.

Parameters
pPort to ignore.

Implemented in odcore::wrapper::POSIX::POSIXUDPReceiver, and odcore::wrapper::WIN32Impl::WIN32UDPReceiver.

void odcore::io::udp::UDPReceiver::setStringListener ( StringListener sl)
virtual

This method sets or unsets a string listener.

Parameters
slStringListener to be set. If set to NULL, observing is suspended.

Implements odcore::io::StringObserver.

void odcore::io::udp::UDPReceiver::setSynchronousPacketListener ( PacketListener pl)

This method sets a synchronous PacketListener to be used instead of decoupled PacketPipeline.

Parameters
plSynchronous PacketListener to use..
virtual void odcore::io::udp::UDPReceiver::start ( )
pure virtual

This method starts the asynchronous UDP receiving.

Implemented in odcore::wrapper::POSIX::POSIXUDPReceiver, and odcore::wrapper::WIN32Impl::WIN32UDPReceiver.

virtual void odcore::io::udp::UDPReceiver::stop ( )
pure virtual

This method stops the asynchronous UDP receiving. A stopped receiving cannot be restarted!

Implemented in odcore::wrapper::POSIX::POSIXUDPReceiver, and odcore::wrapper::WIN32Impl::WIN32UDPReceiver.