blob: f1c8a8d2bb475fd698fdb6f46e165736c84c571a (
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
40
41
42
43
44
45
|
/*
* http://linux.m2osw.com/c-implementation-udp-clientserver
*
* UDPSender.h
*
* Created on: 29.06.2016
* Author: Tobias Frust
*/
#ifndef UDPCLIENT_H_
#define UDPCLIENT_H_
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdexcept>
#include <cstring>
class udp_client_server_runtime_error : public std::runtime_error
{
public:
udp_client_server_runtime_error(const char *w) : std::runtime_error(w) {}
};
class UDPClient {
public:
UDPClient(const std::string& addr, int port);
~UDPClient();
int get_socket() const;
int get_port() const;
std::string get_addr() const;
int send(const char *msg, size_t size);
int msend(int n, struct mmsghdr *msg);
private:
int f_socket;
int f_port;
std::string f_addr;
struct addrinfo * f_addrinfo;
};
#endif /* UDPCLIENT_H_ */
|