载入中...
搜索中...
未找到
UdpSocket.h
浏览该文件的文档.
1#pragma once
2
3#include "NetTypes.h"
4
5#include <cstdint>
6#include <memory>
7#include <mutex>
8#include <string>
9#include <vector>
10
11namespace eve::data {
12class ByteData;
13}
14
15namespace Poco::Net {
16class DatagramSocket;
17}
18
19namespace eve::network {
20
21class Network;
22
24class UdpSocket {
25public:
27 explicit UdpSocket(Network* net);
28 ~UdpSocket();
29
31 bool bind(uint16_t port);
33 bool connect(std::string host, uint16_t port);
35 bool sendTo(eve::data::ByteData* data, std::string host, uint16_t port);
37 bool sendToString(std::string s, std::string host, uint16_t port);
41 bool sendString(std::string s);
43 void close();
44
46 Poco::Net::DatagramSocket* datagram();
48 bool isBound() const { return bound_; }
50 Network* network() const { return net_; }
51
52private:
53 Network* net_ = nullptr;
54 std::unique_ptr<Poco::Net::DatagramSocket> sock_;
55 bool bound_ = false;
56 bool connected_ = false;
57};
58
59} // namespace eve::network
Light2D::Data * data
uint32_t s
Definition Weather.cpp:28
In-memory byte buffer implementing eve::Data (ref-counted).
Definition ByteData.h:11
Network module: TCP/UDP/HTTP factories, background worker, and completion event plumbing....
Definition Network.h:30
UDP socket backed by Poco::Net; supports connect/bind and datagram send.
Definition UdpSocket.h:24
bool sendTo(eve::data::ByteData *data, std::string host, uint16_t port)
Sends a datagram to an explicit host:port.
Definition UdpSocket.cpp:70
Network * network() const
Owning module.
Definition UdpSocket.h:50
Poco::Net::DatagramSocket * datagram()
Internal: underlying Poco datagram socket.
Definition UdpSocket.cpp:18
bool sendToString(std::string s, std::string host, uint16_t port)
Sends a string datagram to an explicit host:port.
Definition UdpSocket.cpp:94
void close()
Closes the socket.
bool bind(uint16_t port)
Binds to a local port; true on success.
Definition UdpSocket.cpp:22
bool sendString(std::string s)
Sends a string datagram to the connected peer.
bool isBound() const
True after bind().
Definition UdpSocket.h:48
bool connect(std::string host, uint16_t port)
Connects to a remote host:port (restricts send()).
Definition UdpSocket.cpp:47
bool send(eve::data::ByteData *data)
Sends a datagram to the connected peer.