Gamedev Framework (gf)  0.19.0
A C++17 framework for 2D games
UdpSocket.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2021 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_UDP_SOCKET_H
22 #define GF_UDP_SOCKET_H
23 
24 #include <cstdint>
25 #include <string>
26 
27 #include "NetApi.h"
28 #include "Socket.h"
29 #include "SocketAddress.h"
30 #include "Span.h"
31 #include "Types.h"
32 
33 namespace gf {
34 #ifndef DOXYGEN_SHOULD_SKIP_THIS
35 inline namespace v1 {
36 #endif
37 
51  class GF_NET_API UdpSocket : public Socket {
52  public:
58  UdpSocket() = default;
59 
70 
80  UdpSocket(const std::string& service, SocketFamily family = SocketFamily::Unspec);
81 
91  SocketAddress getRemoteAddress(const std::string& hostname, const std::string& service);
92 
100  SocketDataResult sendRawBytesTo(Span<const uint8_t> buffer, const SocketAddress& address);
101 
109  SocketDataResult recvRawBytesFrom(Span<uint8_t> buffer, SocketAddress& address);
110 
120  bool sendBytesTo(Span<const uint8_t> buffer, const SocketAddress& address);
121 
131  bool recvBytesFrom(Span<uint8_t> buffer, SocketAddress& address);
132 
133  };
134 
135 #ifndef DOXYGEN_SHOULD_SKIP_THIS
136 }
137 #endif
138 }
139 
140 #endif // GF_UDP_SOCKET_H
SocketFamily
A socket family.
Definition: SocketAddress.h:50
The result of a socket operation.
Definition: SocketTypes.h:89
Semantic type to represent "any".
Definition: Types.h:69
Unspecified (either IPv4 or IPv6)
The namespace for gf classes.
Definition: Action.h:35
A UDP socket.
Definition: UdpSocket.h:51
A network socket.
Definition: Socket.h:41
A socket address.
Definition: SocketAddress.h:78