DTrackSDK  v2.9.0
DTrackNet.hpp
1 /* DTrackNet: C++ header file
2  *
3  * DTrackSDK: functions for receiving and sending UDP/TCP packets.
4  *
5  * Copyright 2007-2021, Advanced Realtime Tracking GmbH & Co. KG
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * Version v2.7.0
31  *
32  */
33 
34 #ifndef _ART_DTRACKNET_H_
35 #define _ART_DTRACKNET_H_
36 
37 namespace DTrackNet {
38 
39 struct _ip_socket_struct; // forward declaration
40 
44 void net_init(void);
45 
49 void net_exit(void);
50 
51 
58 unsigned int ip_name2ip(const char* name);
59 
60 
64 class UDP
65 {
66 public:
67 
74  UDP( unsigned short port, unsigned int multicastIp = 0 );
75 
79  ~UDP();
80 
86  bool isValid();
87 
93  unsigned short getPort();
94 
100  unsigned int getRemoteIp();
101 
112  int receive( void *buffer, int maxLen, int toutUs );
113 
124  int send( const void* buffer, int len, unsigned int ip, unsigned short port, int toutUs );
125 
126 private:
127 
128  bool m_isValid;
129  struct _ip_socket_struct* m_socket;
130  unsigned short m_port;
131  unsigned int m_multicastIp;
132  unsigned int m_remoteIp;
133 };
134 
135 
139 class TCP
140 {
141 public:
142 
149  TCP( unsigned int ip, unsigned short port );
150 
154  ~TCP();
155 
159  bool isValid();
160 
169  int receive( void *buffer, int maxLen, int toutUs );
170 
179  int send( const void* buffer, int len, int toutUs );
180 
181 private:
182 
183  bool m_isValid;
184  struct _ip_socket_struct* m_socket;
185 };
186 
187 
188 } // namespace DTrackNet
189 
190 #endif // _ART_DTRACKNET_H_
191 
int send(const void *buffer, int len, unsigned int ip, unsigned short port, int toutUs)
Send UDP data.
Definition: DTrackNet.cpp:347
Handling TCP data.
Definition: DTrackNet.hpp:139
unsigned short getPort()
Get UDP data port where data is received.
Definition: DTrackNet.cpp:260
~TCP()
Deinitialize TCP socket.
Definition: DTrackNet.cpp:435
int receive(void *buffer, int maxLen, int toutUs)
Receive TCP data.
Definition: DTrackNet.cpp:461
int receive(void *buffer, int maxLen, int toutUs)
Receive UDP data.
Definition: DTrackNet.cpp:278
unsigned int getRemoteIp()
Get IP address of sender of latest received data.
Definition: DTrackNet.cpp:269
Internal socket type.
Definition: DTrackNet.cpp:66
TCP(unsigned int ip, unsigned short port)
Initialize client TCP socket.
Definition: DTrackNet.cpp:394
bool isValid()
Returns if UDP socket is open to receive data.
Definition: DTrackNet.cpp:251
Handling UDP data.
Definition: DTrackNet.hpp:64
int send(const void *buffer, int len, int toutUs)
Send TCP data.
Definition: DTrackNet.cpp:505
bool isValid()
Returns if TCP connection is active.
Definition: DTrackNet.cpp:452
UDP(unsigned short port, unsigned int multicastIp=0)
Initialize UDP socket.
Definition: DTrackNet.cpp:139
~UDP()
Deinitialize UDP socket.
Definition: DTrackNet.cpp:222