载入中...
搜索中...
未找到
eve::network::NetHost类 参考

EVENGINE_API_PLATFORM public API. 更多...

#include <NetHost.h>

Public 类型

using MessageHandler = std::function< void(uint32_t peerId, UdpLink::MsgType, uint8_t channel, const char *, size_t)>
 
using PeerHandler = std::function< void(uint32_t peerId)>
 

Public 成员函数

 NetHost (Network *net)
 Net host.
 
 ~NetHost ()
 Net host.
 
bool start (uint16_t port)
 Starts .
 
void setLossRate (float rate)
 Sets the loss rate.
 
void setTimeoutMs (int ms)
 Sets the timeout ms.
 
void onDatagram (const std::vector< char > &bytes, const std::string &from)
 On datagram.
 
void pump (int64_t nowMs)
 Pump.
 
UdpLink * linkByPeerId (uint32_t peerId) const
 Link by peer id.
 
size_t peerCount () const
 Peer count.
 
void sendTo (uint32_t peerId, UdpLink::MsgType type, uint8_t channel, const void *data, size_t n)
 Send to.
 
bool sendStringTo (uint32_t peerId, UdpLink::MsgType type, uint8_t channel, const std::string &s)
 Send string to.
 
void setMessageHandler (MessageHandler h)
 Sets the message handler.
 
void setPeerConnectedHandler (PeerHandler h)
 Sets the peer connected handler.
 
void setPeerDisconnectedHandler (PeerHandler h)
 Sets the peer disconnected handler.
 

详细描述

EVENGINE_API_PLATFORM public API.

UDP host: one bound socket shared by all peers. Datagrams are routed by the sender address string to a per-peer UdpLink; new addresses get a peer id and emit peerconn. Link death (timeout) emits peerdisconn and removes the peer. All state is main-thread; Network::pump calls onDatagram/pump.

在文件 NetHost.h 第 25 行定义.

成员类型定义说明

◆ MessageHandler

using eve::network::NetHost::MessageHandler = std::function<void(uint32_t peerId, UdpLink::MsgType, uint8_t channel, const char*, size_t)>

在文件 NetHost.h 第 56 行定义.

◆ PeerHandler

using eve::network::NetHost::PeerHandler = std::function<void(uint32_t peerId)>

在文件 NetHost.h 第 58 行定义.

构造及析构函数说明

◆ NetHost()

eve::network::NetHost::NetHost ( Network *  net)
explicit

Net host.

在文件 NetHost.cpp 第 9 行定义.

◆ ~NetHost()

eve::network::NetHost::~NetHost ( )

Net host.

在文件 NetHost.cpp 第 11 行定义.

成员函数说明

◆ linkByPeerId()

UdpLink * eve::network::NetHost::linkByPeerId ( uint32_t  peerId) const

Link by peer id.

在文件 NetHost.cpp 第 76 行定义.

被这些函数引用 sendStringTo() , 以及 sendTo().

◆ onDatagram()

void eve::network::NetHost::onDatagram ( const std::vector< char > &  bytes,
const std::string &  from 
)

On datagram.

在文件 NetHost.cpp 第 43 行定义.

引用了 bytes, d, from, id, n , 以及 t.

◆ peerCount()

size_t eve::network::NetHost::peerCount ( ) const
inline

Peer count.

在文件 NetHost.h 第 47 行定义.

◆ pump()

void eve::network::NetHost::pump ( int64_t  nowMs)

Pump.

在文件 NetHost.cpp 第 70 行定义.

◆ sendStringTo()

bool eve::network::NetHost::sendStringTo ( uint32_t  peerId,
UdpLink::MsgType  type,
uint8_t  channel,
const std::string &  s 
)

Send string to.

在文件 NetHost.cpp 第 87 行定义.

引用了 linkByPeerId(), s, eve::network::UdpLink::sendString() , 以及 type.

◆ sendTo()

void eve::network::NetHost::sendTo ( uint32_t  peerId,
UdpLink::MsgType  type,
uint8_t  channel,
const void *  data,
size_t  n 
)

Send to.

在文件 NetHost.cpp 第 81 行定义.

引用了 linkByPeerId(), n, eve::network::UdpLink::send() , 以及 type.

◆ setLossRate()

void eve::network::NetHost::setLossRate ( float  rate)

Sets the loss rate.

在文件 NetHost.cpp 第 33 行定义.

引用了 rate.

◆ setMessageHandler()

void eve::network::NetHost::setMessageHandler ( MessageHandler  h)
inline

Sets the message handler.

在文件 NetHost.h 第 61 行定义.

引用了 h.

◆ setPeerConnectedHandler()

void eve::network::NetHost::setPeerConnectedHandler ( PeerHandler  h)
inline

Sets the peer connected handler.

在文件 NetHost.h 第 63 行定义.

引用了 h.

◆ setPeerDisconnectedHandler()

void eve::network::NetHost::setPeerDisconnectedHandler ( PeerHandler  h)
inline

Sets the peer disconnected handler.

在文件 NetHost.h 第 65 行定义.

引用了 h.

◆ setTimeoutMs()

void eve::network::NetHost::setTimeoutMs ( int  ms)

Sets the timeout ms.

在文件 NetHost.cpp 第 38 行定义.

◆ start()

bool eve::network::NetHost::start ( uint16_t  port)

Starts .

在文件 NetHost.cpp 第 21 行定义.

引用了 eve::network::UdpSocket::bind() , 以及 eve::network::Network::newUdp().


该类的文档由以下文件生成: