-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDPSocket.h
More file actions
74 lines (51 loc) · 2.01 KB
/
UDPSocket.h
File metadata and controls
74 lines (51 loc) · 2.01 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* File: UDPSocket.h
* Author: msobral
*
* Created on 6 de Julho de 2016, 16:14
*/
#ifndef UDPSOCKET_H
#define UDPSOCKET_H
#include <string>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
#include "BaseSocket.h"
namespace sockpp {
// classe UDPSocket: representa sockets UDP, podendo enviar ou receber datagramas
class UDPSocket : public BaseSocket {
public:
UDPSocket(const AddrInfo &addr);
UDPSocket(int socket_descriptor);
UDPSocket();
UDPSocket(UDPSocket &&orig);
virtual ~UDPSocket();
// define o endereço default do peer
void set_default_peer(const AddrInfo & addr);
// envia os bytes contidos em "data" para o peer especificado em "addr"
int send(const std::vector<char> &data, const AddrInfo &addr);
int send(std::string_view data, const AddrInfo &addr);
// envia os bytes contidos em "data" para o default peer
int send(const std::vector<char> &data);
int send(std::string_view data);
// envia os "numbytes" bytes contidos em "buffer"
int send(const char *buffer, int num_bytes, const AddrInfo &addr);
// recebe até "max_bytes", e retorna-os como um vector<char>
// copia em "addr" o IP e port do remetente
std::vector<char> recv(int max_bytes, AddrInfo &addr);
// recebe até "max_bytes", e retorna-os como um vector<char>
std::vector<char> recv(int max_bytes);
// recebe até MaxDatagramSize e retorna-os como um vector<char>
std::vector<char> recv();
// recebe até MaxDatagramSize e retorna-os como um vector<char>
// copia em "addr" o IP e port do remetente
std::vector<char> recv(AddrInfo& addr);
// recebe até "max_bytes", e grava-os em "buffer"
int recv(char *buffer, int max_bytes, AddrInfo &addr);
int recv(char *buffer, int max_bytes);
const size_t MaxDatagramSize = 8192;
protected:
AddrInfo peer_addr;
};
}
#endif /* UDPSOCKET_H */