Classes | Public Member Functions

CxUtils::UdpSharedServer Class Reference

UDP Server software that can be used to run multiple applications that can receive unicast UDP messages simultaneously. More...

#include <udpsharedserver.h>

List of all members.

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.

Detailed Description

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.


Constructor & Destructor Documentation

UdpSharedServer::UdpSharedServer (  )

Constructor.

Definition at line 191 of file udpsharedserver.cpp.

UdpSharedServer::~UdpSharedServer (  )

Destructor.

Definition at line 209 of file udpsharedserver.cpp.


Member Function Documentation

int UdpSharedServer::GetNetworkInterface (  ) const
Returns:
The network interface being used for UDP receiving. -1 is any.

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.

Parameters:
[in]portThe port to receive on.
[in]multicastGroupThe multicast group to join. Value values are "224.0.0.1-239.255.255.255."
[in]netInterfaceThe network interface to receive on (which network card, etc.) A value of -1 indicates any interface (default).
Returns:
1 on success, 0 on failure.

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
Returns:
True if server is running and valid.

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.

Parameters:
[out]packetThe message data received.
[out]ipAddressIP address of data sender.
Returns:
True on success, false on failure.

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.

Parameters:
[in]callbackFunction callback data.
Returns:
True on success, false on failure.

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.

Parameters:
[in]callbackPointer to callback to be run.
Returns:
True on success, false on failure.

Definition at line 331 of file udpsharedserver.cpp.

void UdpSharedServer::RemoveCallback ( const Callback::Data callback )

Remove a registered callback.

Parameters:
[in]callbackCallback data to remove.

Definition at line 409 of file udpsharedserver.cpp.

void UdpSharedServer::RemoveCallback ( Callback callback )

Remove a registered callback.

Parameters:
[in]callbackCallback 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.

Parameters:
[in]delayTimeMsSets 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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines