[ENet-discuss] ENetPeer structure when reconnecting

Daniel Aquino mr.danielaquino at gmail.com
Fri Jun 19 06:31:17 PDT 2009


actually you do receive an event disconnect when enet gives up connecting...

When i receive a disconnect message I have the information I need in
peer->data to relate it back...

On Fri, Jun 19, 2009 at 5:01 AM, William Brandt<taekvideo at gmail.com> wrote:
> Marc Rochel wrote:
>
> Hi !
>
>
>
> Something related was bugging me some time as well. When you try to connect,
> after a while, if successful, you get a ENET_EVENT_TYPE_CONNECT, but you
> never get a notification when the connection doesn’t get established. Maybe
> enet keeps trying infinitly itself? I “solved” the issue for me by checking
> if some selfdefined timeout is passed and the call enet_host_destroy.
> Creating a new one afterwards and trying to connect again works.
>
>
>
> Best regards
>
>     Marc
>
>
>
>
>
> From: enet-discuss-bounces at cubik.org [mailto:enet-discuss-bounces at cubik.org]
> On Behalf Of William Brandt
> Sent: Donnerstag, 18. Juni 2009 19:08
> To: Discussion of the ENet library
> Subject: Re: [ENet-discuss] ENetPeer structure when reconnecting
>
>
>
> Ruud van Gaal wrote:
>
> This all sounds familiar. I have this connection scheme with the following
>
> properties:
>
> - the server may not be online yet
>
> - the client attempts a connection every second or 2, to see if the server
>
> is already alive
>
> - I only want 1 connection (client<->server)
>
>
>
> I have a C++ wrapper (class QNClient) which only tracks 1 peer. This client
>
> class is legacy and only represents 1 link to a server (class QNServer).
>
> For repeated connection attempts, this was no problem in the past (without
>
> ENet); I sent out some kind of CONNECT packet, and if something came back,
>
> it was connected.
>
> With the ENet peer, I start an enet_host_connect() with every connection
>
> attempt. If I create an ENet host with only 1 peer, I run out of peers after
>
> this first connect attempt.
>
> It's a bit awkward, since if I allow more peers in the ENet host, multiple
>
> peers may connect succesfully. I'll have to drop the surplus of connections
>
> once the server comes up and it turns out I get multiple
>
> ENET_EVENT_TYPE_CONNECT events.
>
> It seems to work though with 1 peer, I just get a lot of 'out of peer' error
>
> when trying enet_host_connect(). I haven't tried resetting the peer; I don't
>
> think I want to since a connect reply may still be incoming and I'd rather
>
> handle that as usual.
>
>
>
> Ruud
>
>
>
>
>
>
>
> -----Oorspronkelijk bericht-----
>
> Van: enet-discuss-bounces at cubik.org
>
> [mailto:enet-discuss-bounces at cubik.org] Namens Daniel Aquino
>
> Verzonden: Thursday, June 18, 2009 18:13
>
> Aan: Discussion of the ENet library
>
> Onderwerp: Re: [ENet-discuss] ENetPeer structure when reconnecting
>
>
>
> Perhaps as I said you ran out of peers...  So until the
>
> callback stack was finished that peer wouldn't be free yet...
>
>
>
> On Wed, Jun 17, 2009 at 11:23 PM, William
>
> Brandt<taekvideo at gmail.com> wrote:
>
>
>
> Daniel Aquino wrote:
>
>
>
> >From what i know there is no deleting.  I believe enet
>
>
>
> will clean up
>
>
>
> the peer after it has told you about the event and you have had a
>
> chance to react.  And the connection function will return a
>
>
>
> new peer
>
>
>
> with no way to re-use the existing peer that I know of...
>
>
>
> Which does
>
>
>
> confuse me a bit in the case of attempting to make a new connection
>
> inside of the disconnection event when there is no more
>
>
>
> peers left...
>
>
>
> I don't know if in that case it would still consider that peer as
>
> valid resulting in the inability to form a new connection or if it
>
> would end up using that same peer destroying data inside of it that
>
> you may still need...  So I copied any data I needed from the peer
>
> object before making the new connection just in case...   I guess
>
> these questions could be solved easily by looking into the
>
>
>
> enet code
>
>
>
> or setting the peer count to 1 and doing some testing...
>
>
>
> On Wed, Jun 17, 2009 at 2:47 PM, William
>
>
>
> Brandt<taekvideo at gmail.com> wrote:
>
>
>
>
>
> When a user is disconnected from the server and is
>
>
>
> reconnecting, do I
>
>
>
> need to get a new ENetPeer object (from the enet_host_connect()
>
> function), or is it possible to use the same one to
>
>
>
> reconnect?  Also,
>
>
>
> if I have to get a new one, do I need to delete the old one (& how)?
>
>
>
> ...
>
>
>
> well what I'm doing now seems to be working...
>
> the main problem I was having was that enet_host_connect() was
>
> returning NULL when I tried to reconnect.  It seems I had to
>
> explicitly call
>
> enet_peer_reset() on the old peer object before I reconnect
>
>
>
> and get a
>
>
>
> new peer object.
>
>
>
>
>
> _______________________________________________
>
> ENet-discuss mailing list
>
> ENet-discuss at cubik.org
>
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
>
>
>
>
> You should add a 5000ms delay when you call enet_host_service() to check for
> connect events after calling enet_host_connect().  Then if you don't get a
> response you can safely assume that the server isn't going to respond and
> reset the peer then try again.
>
> ________________________________
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
>
> you can do that in one line.  It's safe to assume that you won't get any
> events other than a connection confirmation if you're not connected... so
> you can use the enet_host_service() built-in timeout feature.  This is what
> I use (in a connect() function that returns true when connection succeeded
> or false when it failed):
>
> peer_ = enet_host_connect (client_, &address, 2);
> if (peer_ == NULL) throw "ERROR: Unable to initiate Enet peer connection.";
> if (enet_host_service (client_, &event, 5000) > 0 && event.type ==
> ENET_EVENT_TYPE_CONNECT) return true;
> else{
>         enet_peer_reset (peer_);
>         return false;
> }
>
> _______________________________________________
> 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