Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
UdpSocket.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 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
33namespace gf {
34#ifndef DOXYGEN_SHOULD_SKIP_THIS
35inline 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
101
110
120 bool sendBytesTo(Span<const uint8_t> buffer, const SocketAddress& address);
121
132
133 };
134
135#ifndef DOXYGEN_SHOULD_SKIP_THIS
136}
137#endif
138}
139
140#endif // GF_UDP_SOCKET_H
A socket address.
Definition: SocketAddress.h:78
A network socket.
Definition: Socket.h:41
A UDP socket.
Definition: UdpSocket.h:51
bool sendBytesTo(Span< const uint8_t > buffer, const SocketAddress &address)
Send a whole buffer to the socket.
SocketAddress getRemoteAddress(const std::string &hostname, const std::string &service)
Get a remote address for this socket.
bool recvBytesFrom(Span< uint8_t > buffer, SocketAddress &address)
Receive a whole buffer from the socket.
UdpSocket(const std::string &service, SocketFamily family=SocketFamily::Unspec)
Full constructor.
SocketDataResult recvRawBytesFrom(Span< uint8_t > buffer, SocketAddress &address)
Receive some bytes from the socket.
UdpSocket(AnyType, SocketFamily family=SocketFamily::Unspec)
Full constructor.
SocketDataResult sendRawBytesTo(Span< const uint8_t > buffer, const SocketAddress &address)
Send some bytes over to the socket.
UdpSocket()=default
Default constructor.
SocketFamily
A socket family.
Definition: SocketAddress.h:50
@ Unspec
Unspecified (either IPv4 or IPv6)
The namespace for gf classes.
Semantic type to represent "any".
Definition: Types.h:69
The result of a socket operation.
Definition: SocketTypes.h:89