[ENet-discuss] Connection/disconnection event don't print

Eugenio Favalli eugenio.favalli at alice.it
Fri Sep 2 10:25:50 PDT 2005


I'm sorry to paste lines of code here, but else it will take me a year 
to explain. This is my server code, copied from the tutorial:

    while (true)
    {

        ENetEvent event;
        /* Wait up to 1000 milliseconds for an event. */
        enet_host_service(server, &event, 2000);
        //printf("%i: %i\n", i, event.type);
        i++;

            switch (event.type)
            {
                case ENET_EVENT_TYPE_CONNECT:
                    printf("A new client connected from %x:%u.\n",
                           event.peer->address.host,
                           event.peer->address.port);
                    /* Store any relevant client information here. */
                    event.peer->data = (void *)"Client information";
                    break;
                case ENET_EVENT_TYPE_RECEIVE:
                    printf("A packet of length %u containing '%s' was 
received from %s on channel %u.\n",
                            event.packet->dataLength,
                            event.packet->data,
                            event.peer->data,
                            event.channelID);
                    /* Clean up the packet now that we're done using it. */
                    enet_packet_destroy(event.packet);
                    break;
                case ENET_EVENT_TYPE_DISCONNECT:
                    printf("%s disconected.\n", event.peer->data);
                    /* Reset the peer's client information. */
                    event.peer->data = NULL;
                    break;
                case ENET_EVENT_TYPE_NONE:
                    printf("No event\n");
                    break;
                default:
                    printf("Unknown event\n");
                    break;
            }
    }

Everything seems to be working, I can receive packets and everityng 
else. The problem is that when I connect with the client it doesn't 
write "a new client connected from..." but i'm sure it executes the case 
statement since when i send a packet from the client the 
event.peer->data is right.

Thank you for the help
Regards,
Eugenio


More information about the ENet-discuss mailing list