Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
UDPServer.hh
1 #ifndef __UDPSERVER__
2 #define __UDPSERVER__
3 
4 #include <bias_config.h>
5 
6 #include "UDPServerClientDefinitions.hh"
7 #include <Base/Debug/Debug.hh>
8 
9 
10 #ifdef WIN32
11 #include <winsock.h>
12 #else
13 #include <netinet/in.h>
14 #endif
15 
16 
17 #define D_UDP_SEND 0x00000001
18 namespace BIAS {
19 
20 
21 /**
22  @class UDPServer
23  @brief UDP server class
24  @ingroup network
25  @author Ingo Thomsen
26  */
27 class BIASNetworkComm_EXPORT UDPServer : public BIAS::Debug {
28 
29 public:
30 
31  /**
32  Constructor,
33  @author Ingo Thomsen
34  */
35  UDPServer();
36  /** open a UDP socket to the given host:port
37  @author evers */
38  int Connect(const char* ipaddress_or_name, int port, bool UseTCP = false);
39 
40  /** open a UDP socket to the given port
41  @author Ingo Schiller */
42  int Connect(int port, bool UseTCP = false);
43 
44  int Disconnect();
45 
46  /**
47  Send a message
48  @author Ingo Thomsen
49  @param message A char pointer to the beginning of the message
50  @param message_size The Size of the message
51  @return -1 in any case of failure, otherwise the number of
52  UDP packages successfully sent
53  */
54  int Send (const char *message, const size_t message_size);
55 
56  /**
57  Send a message to a given host:port (UDP only)
58  @author mfranke
59  @param message A char pointer to the beginning of the message
60  @param message_size The size of the message
61  @param ipAddress The host ip address
62  @param port The host port
63  @return -1 in any case of failure, otherwise the number of
64  UDP packages successfully sent
65  */
66  int SendToUDP (const char* message, const size_t message_size,
67  const char* ipAddress, int port);
68 
69  /**
70  Destructor
71  @author Ingo Thomsen
72  */
73  ~UDPServer();
74 
75 
76  void SetThrottle(const unsigned int t) {Throttle_ = t;}
77  unsigned int GetMessageSize(){return MessageSize_;}
78 
79 protected:
80 
81  // socket address
82  struct sockaddr_in UDPSockAddr_;
83  struct sockaddr TCPSockAddr_;
84  // descriptor of the UDP socket
86 
87  // send buffer
88  char* send_buffer_;
89 
90  // ring counter for messages sent, maximimum defined in
91  // UDPServerClientDefinitions.hh, included by UPDServer.cc
93 
94  // to prevent UDP-packet collision on the receiver side, use Throttle_
95  // (in ms) to sleep between packets
96  unsigned int Throttle_;
97  // total size of messagte including all header
98  unsigned int MessageSize_;
99 
101 
102  // this buffer contains struct ImageHeader + data
103  char *ImgBuffer_;
104  // and has this size
105  unsigned int ImgBufferSize_;
106 
107 
108 }; // class UDPServer
109 
110 
111 
112 } // namespace BIAS
113 #endif
int socket_descriptor_
Definition: UDPServer.hh:85
char * ImgBuffer_
Definition: UDPServer.hh:103
unsigned int ImgBufferSize_
Definition: UDPServer.hh:105
unsigned int MessageSize_
Definition: UDPServer.hh:98
unsigned int GetMessageSize()
Definition: UDPServer.hh:77
char * send_buffer_
Definition: UDPServer.hh:88
bool TCPinsteadOfUDP_
Definition: UDPServer.hh:100
unsigned int Throttle_
Definition: UDPServer.hh:96
int message_counter_
Definition: UDPServer.hh:92
void SetThrottle(const unsigned int t)
Definition: UDPServer.hh:76
UDP server class.
Definition: UDPServer.hh:27