AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
udpSocket.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-network-export.hpp"
23
24#include <cstddef>
25#include <string>
26#include <string_view>
27
28#include "network/socket.hpp"
29
30namespace anch::network {
31
40 class ANCH_NETWORK_EXPORT UdpSocket {
41
42 // Attributes +
43 public:
45 static constexpr std::size_t MAX_DATAGRAM_SIZE = 65507;
46
47 private:
50 // Attributes -
51
52 // Constructors +
53 public:
62 explicit UdpSocket(const std::string& host = "", uint16_t port = 0);
63 // Constructors -
64
65 // Methods +
66 public:
75 void sendTo(std::string_view data, const anch::network::Address& to);
76
86 void sendTo(std::string_view data, const std::string& host, uint16_t port);
87
98 anch::network::Address receiveFrom(std::string& data, std::size_t maxSize = MAX_DATAGRAM_SIZE);
99
108
115 // Methods -
116
117 };
118
119} // anch::network
Socket address (IPv4 or IPv6 address and port).
Definition address.hpp:54
Network socket (POSIX).
Definition socket.hpp:63
anch::network::Address getAddress() const
anch::network::Address receiveFrom(std::string &data, std::size_t maxSize=MAX_DATAGRAM_SIZE)
void sendTo(std::string_view data, const std::string &host, uint16_t port)
void sendTo(std::string_view data, const anch::network::Address &to)
anch::network::Socket & getSocket() noexcept
UdpSocket(const std::string &host="", uint16_t port=0)
static constexpr std::size_t MAX_DATAGRAM_SIZE
Definition udpSocket.hpp:45
Network namespace.
Definition address.hpp:30