UDP Server software that can be used to run multiple applications that can receive unicast UDP messages simultaneously. More...
#include <udpsharedserver.h>
Classes | |
class | Callback |
Callback class used for getting UDP messages received by the shared server socket. More... | |
class | Info |
Data structure to store socket information. More... | |
Public Member Functions | |
UdpSharedServer () | |
Constructor. | |
~UdpSharedServer () | |
Destructor. | |
int | InitializeSocket (const unsigned short port, const IP4Address &multicastGroup="224.0.0.1", const int netInterface=-1) |
Initializes a shared UDP socket on a port with a specific network interface. This method also will join a multicast group to get multicast messages. | |
void | Shutdown () |
Shutsdown the UDP Server. | |
int | GetNetworkInterface () const |
bool | RegisterCallback (Callback *callback) |
Register a callback to be run whenever a new message is received. | |
bool | RegisterCallback (const Callback::Data &callback) |
Register a function callback to be run whenever a new message is received. | |
void | RemoveCallback (Callback *callback) |
Remove a registered callback. | |
void | RemoveCallback (const Callback::Data &callback) |
Remove a registered callback. | |
bool | IsValid () const |
bool | IsPrimary () const |
Return true if this instance is the active UDP socket, otherwise false. | |
bool | IsConnected () const |
bool | Recv (Packet &packet, IP4Address &ipAddress) |
Whenever a message is recieved it is added to a queue or shared through a callback. This function pulls a message from the queue in FIFO order. | |
void | SetUpdateDelayMs (const unsigned int delayTimeMs=0) |
Sets delay in polling for incomming messages loop. |
UDP Server software that can be used to run multiple applications that can receive unicast UDP messages simultaneously.
This class/software was developed to deal with an issue in UDP communication. Normally, if you have to applications running on a single computer, and both are running a UDP Server on the same port number, only one of the processes will receive unicast messages sent to the computer. This software removes this restriction using a shared memory to communicate between this applications and share UDP traffic received. Therefore, if you use this code in your program, you can run your application multiple times on a single machine and all applications will receive unicast and multicast/broadcast UDP data sent to your computer.
If you use any other software that receives UDP data on the port your are using then this software will not function as expected. In order to work, all of your applications receiving on the same UDP port must use this code. Therefore, this software should only be used in very specific instances and custom applications/environments.
Definition at line 83 of file udpsharedserver.h.
UdpSharedServer::UdpSharedServer | ( | ) |
Constructor.
Definition at line 191 of file udpsharedserver.cpp.
UdpSharedServer::~UdpSharedServer | ( | ) |
Destructor.
Definition at line 209 of file udpsharedserver.cpp.
int UdpSharedServer::GetNetworkInterface | ( | ) | const |
Definition at line 315 of file udpsharedserver.cpp.
int UdpSharedServer::InitializeSocket | ( | const unsigned short | port, |
const IP4Address & | multicastGroup = "224.0.0.1" , |
||
const int | netInterface = -1 |
||
) |
Initializes a shared UDP socket on a port with a specific network interface. This method also will join a multicast group to get multicast messages.
If an existing UDP Shared Server is running on your system with the same port, but a different multicastGroup (or is unicast) then this method will fail.
[in] | port | The port to receive on. |
[in] | multicastGroup | The multicast group to join. Value values are "224.0.0.1-239.255.255.255." |
[in] | netInterface | The network interface to receive on (which network card, etc.) A value of -1 indicates any interface (default). |
Definition at line 235 of file udpsharedserver.cpp.
bool CxUtils::UdpSharedServer::IsConnected | ( | ) | const [inline] |
Definition at line 154 of file udpsharedserver.h.
bool UdpSharedServer::IsPrimary | ( | ) | const |
Return true if this instance is the active UDP socket, otherwise false.
Definition at line 448 of file udpsharedserver.cpp.
bool UdpSharedServer::IsValid | ( | ) | const |
Definition at line 433 of file udpsharedserver.cpp.
bool UdpSharedServer::Recv | ( | Packet & | packet, |
IP4Address & | ipAddress | ||
) |
Whenever a message is recieved it is added to a queue or shared through a callback. This function pulls a message from the queue in FIFO order.
[out] | packet | The message data received. |
[out] | ipAddress | IP address of data sender. |
Definition at line 466 of file udpsharedserver.cpp.
bool UdpSharedServer::RegisterCallback | ( | const Callback::Data & | callback ) |
Register a function callback to be run whenever a new message is received.
[in] | callback | Function callback data. |
Definition at line 357 of file udpsharedserver.cpp.
bool UdpSharedServer::RegisterCallback | ( | Callback * | callback ) |
Register a callback to be run whenever a new message is received.
[in] | callback | Pointer to callback to be run. |
Definition at line 331 of file udpsharedserver.cpp.
void UdpSharedServer::RemoveCallback | ( | const Callback::Data & | callback ) |
Remove a registered callback.
[in] | callback | Callback data to remove. |
Definition at line 409 of file udpsharedserver.cpp.
void UdpSharedServer::RemoveCallback | ( | Callback * | callback ) |
Remove a registered callback.
[in] | callback | Callback data to remove. |
Definition at line 389 of file udpsharedserver.cpp.
void UdpSharedServer::SetUpdateDelayMs | ( | const unsigned int | delayTimeMs = 0 ) |
Sets delay in polling for incomming messages loop.
[in] | delayTimeMs | Sets the time between checking for messages. |
Definition at line 492 of file udpsharedserver.cpp.
void UdpSharedServer::Shutdown | ( | ) |
Shutsdown the UDP Server.
Definition at line 271 of file udpsharedserver.cpp.