[ENet-discuss] how to know when it's safe to call enet_peer_send()?

eye at dihalt.com eye at dihalt.com
Mon Mar 17 14:25:50 PDT 2008


Thank you for an answer.

I have just tested the code. There is a little problem:
peer->windowsSize is a constant value of
ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE (32768) if network speed
is not set. And i can't set or test network speed for
end-user programs - speed can be very different each
minute. 32768 is a big value. On slow GPRS networks and
medium size packets (~1k) sending 32768/1024 = 32 packets
will surely lead to ACK timeout :(.

So a code:

for(; ::enet_host_service(poHost, &oEvent, 0) >= 0);)
{
  if(poPeer->reliableDataInTransit + 1124 >
     peer -> windowSize) continue;

  ENetPacket *poPacket = ::enet_packet_create(pbData,
    ENET_PACKET_FLAG_RELIABLE);
  _ASSERT(poPacket);
  _VERIFY(0 == ::enet_peer_send(poPeer, 0, poPacket));
}

will disconnect by ACK timeouts (protocol.cpp, line 1172)
in half of test cases :(. Is it any way to prevent
disconnections but don't use a
send-packet-wait-ack-send-next slow pattern?


On Sun, 16 Mar 2008 19:19:05 -0700
 Lee Salzman <lsalzman1 at cox.net> wrote:
> Use something like:
> 
>   if (peer -> reliableDataInTransit +
> size_of_packet_you_wish_to_send + 
> 100 < peer -> windowSize)
>      ...
> 
> where that "100" value is just a margin/fudge value to
> account for 
> packet headers and such.
> 
> Lee
> 
> eye at dihalt.com wrote:
> > Hello.
> >
> > I'm new to enet and in the process of testing it right
> now.
> > I'm interested is it possible to send huge amounts of
> data
> > (audio, video etc) using enet. For now i have a few
> > questions and will be happy is someone experienced with
> > ENET will write me a few words of wisdom.
> >
> > 1. Let's assume that we have a fast network (100
> megabit+)
> > and a fast computer (3Ghz+). How to call
> enet_peer_send()
> > so it will not eat all memory? Following example of
> > "unlimited speed test" just eats up all memory becouse
> data
> > is supplied to enet faster than enet can send it over
> > network:
> >
> > for(; ::enet_host_service(poHost, &oEvent, 0) >= 0);)
> > { // timeout '0' is used to achiev speed > 1k packets /
> sec
> >   ENetPacket *poPacket = ::enet_packet_create(pbData,
> 1024,
> >     ENET_PACKET_FLAG_RELIABLE);
> >   _ASSERT(poPacket);
> >   _VERIFY(0 == ::enet_peer_send(poPeer, 0, poPacket));
> > }
> >
> > So i need to somehow make pauses between
> enet_peer_send()
> > calls to give enet
> > a chance to send previously queued data over network.
> Ok,
> > following code will do a deal:
> >
> > for(; ::enet_host_service(poHost, &oEvent, 0) >= 0);)
> > {
> >   // do some magic: if > 64k of data is sent but is not
> > ACK'ed yet - don't
> >   // send new data to prevent overflow
> >   if(poPeer->reliableDataInTransit > 1024*64) continue;
> >
> >   ENetPacket *poPacket = ::enet_packet_create(pbData,
> 1024,
> >     ENET_PACKET_FLAG_RELIABLE);
> >   _ASSERT(poPacket);
> >   _VERIFY(0 == ::enet_peer_send(poPeer, 0, poPacket));
> > }
> >
> > But if this method is correct, it leads to a second
> > question:
> >
> > 2. What is the best method to determine if it's ok to
> make
> > a enet_peer_send() call or not? For example, previous
> > example uses hard-coded limit equal to 64kb of unacked
> data
> > in transit. But such limit will result in unacked
> packets
> > (and disconnection) on slow GPRS connection where speed
> is
> > 4-10 kb/sec and 1000ms is a common png value. Vise
> versa,
> > on 100 megabit network this 64k limit will slow down a
> > process since network can handle much more data in
> transit.
> >
> > So, i'm confused a bit about how to send huge amounts
> of
> > data with good speed on good connections AND no
> disconnects
> > on bad connections. Any ideas? My current code analyses
> > network speed and maintains ~ 1 seconds of data to be
> in
> > transit. But this slows down transfer on fast
> connection,
> > and on artifical 14kbit simulated network huge enough
> > packets (like 16kb per packet) still gives disconnects
> :(.
> > _______________________________________________
> > ENet-discuss mailing list
> > ENet-discuss at cubik.org
> > http://lists.cubik.org/mailman/listinfo/enet-discuss
> >
> >   
> 
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss



More information about the ENet-discuss mailing list