udpreceiver.h
Go to the documentation of this file.
1 #ifndef UDPRECEIVER_H
2 #define UDPRECEIVER_H
3 
4 #define UNIX
5 #ifdef UNIX
6 #include <arpa/inet.h>
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #endif
10 
11 #ifdef WIN32
12 #include<stdio.h>
13 #include<winsock2.h>
14 #pragma comment(lib,"ws2_32.lib")
15 #endif
16 
17 #include <iostream>
18 
20 {
21 public:
22  UDPReceiver();
23  ~UDPReceiver();
24 
25  /* Initialize the class with port and ip what to use on local interface
26  * port = port where to receive data
27  * interface = ip of local interface where to receive data(255.255.255.255 for all)
28  */
29  bool init(int port, std::string localInterface);
30 
31  /* Receives data from the port. Waits for data maximum of timeoutMicroSec
32  * data = pointer to buffer where to save data
33  * dataSize = size of the buffer
34  */
35  int receive(void *data, unsigned int dataSize, int timeoutMicroSec);
36 
37 private:
38  // My address
39  struct sockaddr_in siMe_;
40  // The other computers address
41  struct sockaddr_in siOther_;
42  int sock_;
43  int slen_;
44 
45  bool initOK;
46 
47 #ifdef WIN32
48  WSADATA wsa;
49 #endif
50 };
51 
52 #endif // UDPRECEIVER_H
int receive(void *data, unsigned int dataSize, int timeoutMicroSec)
Definition: udpreceiver.cpp:98
bool init(int port, std::string localInterface)
Definition: udpreceiver.cpp:33
struct sockaddr_in siOther_
Definition: udpreceiver.h:41
struct sockaddr_in siMe_
Definition: udpreceiver.h:39


ifm_o3mxxx
Author(s):
autogenerated on Mon Jun 10 2019 13:34:12