summaryrefslogtreecommitdiffstats
path: root/src/UDPServer/UDPServer.h
blob: 7eef79654712a9a41ad3f04531d80eb9c68cbd26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * http://linux.m2osw.com/c-implementation-udp-clientserver
 *
 * UDPServer.h
 *
 *  Created on: 29.06.2016
 *      Author: Tobias Frust
 */

#ifndef UDPSERVER_H_
#define UDPSERVER_H_

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdexcept>
#include <string>

class UDPServer
{
public:
  UDPServer(const std::string& addr, int port);
  ~UDPServer();

  int                 get_socket() const;
  int                 get_port() const;
  std::string         get_addr() const;

  int                 recv(char *msg, size_t max_size);
  int                 timed_recv(char *msg, size_t max_size, int max_wait_ms);

private:
  int                 f_socket;
  int                 f_port;
  std::string         f_addr;
  struct addrinfo *   f_addrinfo;
};

#endif /* UDPSERVER_H_ */