MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SendPacketToPeer

Function SendPacketToPeer

Source/Engine/Networking/Drivers/ENetDriver.cpp:36–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36void SendPacketToPeer(ENetPeer* peer, const NetworkChannelType channelType, const NetworkMessage& message)
37{
38 // Covert our channel type to the internal ENet packet flags
39 const ENetPacketFlag flag = ChannelTypeToPacketFlag(channelType);
40
41 // This will copy the data into the packet when ENET_PACKET_FLAG_NO_ALLOCATE is not set.
42 // Tho, we cannot use it, because we're releasing the message right after the send - and the packet might not
43 // be sent, yet. To avoid data corruption, we're just using the copy method. We might fix that later, but I'll take
44 // the smaller risk.
45 ENetPacket* packet = enet_packet_create(message.Buffer, message.Length, flag);
46
47 // And send it!
48 enet_peer_send(peer, 0, packet);
49
50 // TODO: To reduce latency, we can use `enet_host_flush` to flush all packets. Maybe some API, like NetworkManager::FlushQueues()?
51}
52
53ENetDriver::ENetDriver(const SpawnParams& params)
54 : ScriptingObject(params)

Callers 1

SendMessageMethod · 0.85

Calls 3

ChannelTypeToPacketFlagFunction · 0.85
enet_packet_createFunction · 0.85
enet_peer_sendFunction · 0.85

Tested by

no test coverage detected