载入中...
搜索中...
未找到
UdpSocket.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "NetTypes.h"
6
7#include <cstdint>
8#include <memory>
9#include <mutex>
10#include <string>
11#include <vector>
12
13namespace eve::data {
14class ByteData;
15}
16
17namespace Poco::Net {
18class DatagramSocket;
19}
20
21namespace eve::network {
22
23class Network;
24
31public:
33 explicit UdpSocket(Network* net);
35 ~UdpSocket();
36
38 bool bind(uint16_t port);
40 bool connect(std::string host, uint16_t port);
42 bool sendTo(eve::data::ByteData* data, std::string host, uint16_t port);
44 bool sendToString(std::string s, std::string host, uint16_t port);
46 bool send(eve::data::ByteData* data);
48 bool sendString(std::string s);
50 void close();
51
53 Poco::Net::DatagramSocket* datagram();
55 bool isBound() const { return bound_; }
57 Network* network() const { return net_; }
58
59private:
60 struct SendState;
61 std::shared_ptr<SendState> sendState_;
62 Network* net_ = nullptr;
63 std::unique_ptr<Poco::Net::DatagramSocket> sock_;
64 bool bound_ = false;
65 bool connected_ = false;
66};
67
68} // namespace eve::network
const std::string & s
#define EVENGINE_API_PLATFORM
Definition Export.h:107
UIHostHandle host
In-memory byte buffer implementing eve::Data (ref-counted).
Definition ByteData.h:13
Network module: TCP/UDP/HTTP factories, background worker, and completion event plumbing....
Definition Network.h:39
UDP socket backed by Poco::Net; supports connect/bind and datagram send. @ownership The caller owns t...
Definition UdpSocket.h:30
Network * network() const
Owning module.
Definition UdpSocket.h:57
bool isBound() const
True after bind().
Definition UdpSocket.h:55