[ENet-discuss] Peer sessionID as key?

Ruud van Gaal ruud at racer.nl
Sat Jan 9 02:17:28 PST 2010


Using the same here, upon a connect in the server c++ class:

      c->id=event.peer->incomingPeerID+70;  // Avoid using id as index!
      event.peer->data=(char*)(c->id);      // Store id in ENet peer

Then when packets come in at the server:

    if(event.type==ENET_EVENT_TYPE_RECEIVE)
    {
      int        nClient;
      qnClientID id;

      id=(qnClientID)event.peer->data;
      nClient=FindClient(id);
      if(nClient<0)
      {
        qerr("QNServer::Receive; unknown client");
        return 0;
      }
      Client *c=&client[nClient];
...
    }

Seems to work ok (for a couple of years now). Just keep enough room for more
ID's than the max number of clients that can connect, as id's can grow
beyond that as disconnects and reconnects happen (I don't make assumptions
about max(incomingPeerID).

Cheers,
Ruud

> -----Oorspronkelijk bericht-----
> Van: enet-discuss-bounces at cubik.org 
> [mailto:enet-discuss-bounces at cubik.org] Namens Andrew Fenn
> Verzonden: Saturday, January 09, 2010 08:29
> Aan: Discussion of the ENet library
> Onderwerp: Re: [ENet-discuss] Peer sessionID as key?
> 
> I'm making a lot of use of peer->incomingPeerID in my 
> program. Does this mean that I shouldn't be using this?
> 
> On Sat, Jan 9, 2010 at 10:11 AM, Lee Salzman 
> <lsalzman1 at cox.net> wrote:
> > Don't use sessionID at all. It's an internal thing that is not even 
> > unique across peers.
> >
> > Inside ENetPeer there is a "void *data". Set that to point 
> to whatever 
> > user data you want. ENet doesn't touch it at all, and it is 
> there for 
> > this purpose.
> >
> > Lee
> >
> > Eugene Marcotte wrote:
> >>
> >> Hi,
> >>
> >> I'm trying to build a mechanism to lookup peers. I have a 
> sort of c++ 
> >> wrapper in the works, and as part of that I am trying to 
> map between 
> >> the peers in events and my c++ peer objects.
> >> I'm currently using the sessionId to key off of the peer, 
> which has 
> >> been working well mostly. However, I just added some 
> 'cleanup' code 
> >> for handling disconnections. When I receive a disconnect 
> event in my 
> >> client (its a 1-1 client server at the moment) I get a 
> sessionId of 
> >> 0. It seems to have the correct ID when the server gets a 
> disconnect 
> >> event.
> >> Is this expected, or am I perhaps doing something wrong? 
> Is there a 
> >> better value to key the peers off of?
> >>
> >> Thanks,
> >> Eugene
> >>
> >
> > _______________________________________________
> > 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