We divide receiving and sending like this (see below) to get all incoming packets before sending outgoing. This function is called once per game frame. This also makes sure any acks to received reliable packets are packed in with your send before you send. That ended up being a huge bandwidth saver for us when trying to send 30 updates a second (it cut the number of packets in half, thus half the IP/UDP overhead). The main piece we added to enet to make this work was a 4th parameter to enet_host_service that lets of disallow it from sending commands. If people are interested, I can post a diff or submit this somehow.<br>
<br>The aggregation bit around the flush is where we merge multiple frames worth of packets for large games (if there are more than 4 players, we only send 15 times per second).<br><br><br>void Socket::_ServiceOnce(bool allowSend)<br>
{<br> ENetEvent event;<br> while ( enet_host_service(m_pNetwork, &event, 0, 0) > 0 )<br> {<br> m_aEventQueue.AddData(event);<br> }<br> if (allowSend)<br> {<br> m_fullServiceCount += 1;<br>
if (++m_curAggregation >= m_maxAggregation)<br> {<br> m_curAggregation = 0;<br> enet_host_flush(m_pNetwork, 1);<br> }<br> }<br>}<br><br><br>Chris<br><br><br><div class="gmail_quote">
On Mon, Sep 13, 2010 at 2:12 PM, Beau Albiston <span dir="ltr"><<a href="mailto:BAlbiston@totimm.com">BAlbiston@totimm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal">Hello All,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I’m particularly interested in how people are dealing
with the enet_host_service blocking on receive when you have things to send…</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I have solved this problem already, but was curious as to
how others have solved the same problem. My solution involved making
(only for Win32 in my case) modifications to the enet_socket_wait function to
allow waiting on socket send and receive, as well as a “cancel wait”
event object (using WSAEventSelect, and WSAWaitForMultipleObjects). I
then added an additional function (enet_socket_cancel_wait) that signals the “cancel
wait” event object and wakes the network thread. From there, the
enet_host_service function returns with a timeout event from which I can then pluck
a queued send command from my queue (using lock-free queues). So, my main
thread queues a send command and then calls enet_socket_cancel_wait to wake the
network thread (in case it is waiting on recv) to process the send command.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">(Lee, if you’re interested in the changes, I can send
them to you.)</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Thanks,</p>
<p class="MsoNormal">-Beau</p>
</div>
</div>
<br>_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br></blockquote></div><br>