[ENet-discuss] Disconnect detection

Eric Boniface eric.boniface at inrialpes.fr
Fri Feb 11 09:11:00 PST 2005


Hello,

I am a newbie to eNet and I try to write very basic client/server
programs.

In fact, the server send every 3 sec a message (string "packet") to all
connected clients.

I try to catch a client disconnection, but I do not succeed.

I put something similar to the server.cpp program from the cubeengine
source, as you can see below.
The problem is that each time the client disconnect, I receive a
negative value (event.peer->data is <0) so I do not change the type
field value.

In fact, I do not understand clearly what is the event.peer->data value.

Any idea ?? Suggestion ??

Thanks in advance,
Eric.

case ENET_EVENT_TYPE_CONNECT:
    cerr << "-I- A new client connected from ";
    cerr << event.peer -> address.host << ":";
    cerr << event.peer -> address.port << "\n";

    newhost = new client; // client is a structure containing ENetPeer
*, string hostname, and so on
    newhost->type = 1; // Connected
    newhost->peer = event.peer;
    char hn[1024];
    newhost->hostname = (enet_address_get_host(&newhost->peer->address,
hn, sizeof(hn))==0) ? hn : "localhost";
    
    cerr<<"Connection of %s\n", newhost->hostname.c_str());
    
    addhost(newhost); // this function add the new host in a vector
object
    event.peer -> data = (void *)(newhost-&peers[0]);
 break;

case ENET_EVENT_TYPE_DISCONNECT:
   if((int)event.peer->data<0) break;
   printf("disconnected client : \n");
   printf("                    (%s)\n",
peers[(int)event.peer->data].hostname.c_str());
   printf("                    %x\n", event.peer->data);
   printf("                    %d\n", (int)event.peer->data);

   peers[(int)event.peer->data].type = 0; // disconnected.
   event.peer->data = (void *)-1;
 break;

--
___________________________________________________________________
 Eric Boniface
 Equipe e-Motion / Projet Parkview
 *********************************
Tél. : (33).(0)4.76.61.55.82
 INRIA ­ Rhône-Alpes
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.puremagic.com/pipermail/enet-discuss/attachments/20050211/3e87e20c/attachment.pgp


More information about the ENet-discuss mailing list