[ENet-discuss] help

Bjørn Lindeijer bjorn at lindeijer.nl
Fri Apr 25 04:03:50 PDT 2008


On 4/25/08, peng zou <samneg at gmail.com> wrote:
>    client = enet_host_create (NULL, 10, 57600, 14400);
>
>    if(client == NULL)
>    {
>       cout<<"Client create failed"<<endl;
>       exit (EXIT_FAILURE);
>    }
>
>    ENetAddress address;
>    ENetPeer *peer;
>
>    enet_address_set_host (& address, "127.0.0.1") ;
>     address.port = 5555;
>
>    while (peer = enet_host_connect (client, & address, 2), peer == NULL)
>    {
>       Sleep(100);
>    }

I think here is where you make an error. If you read the Tutorial [1]
on the website, you'll see that they actually call this method only
once and it returns immediately (ie. it does not mean that the peer is
already connected). You'll have to call enet_host_service on the
client as well for the connection to actually take place.

See at the bottom of the tutorial, where it says:

/* Wait up to 5 seconds for the connection attempt to succeed. */
    if (enet_host_service (client, & event, 5000) > 0 &&
      event.type == ENET_EVENT_TYPE_CONNECT)

But I would really recommend you read all of the tutorial if you
haven't already.

Regards,
Bjørn

[1] http://enet.bespin.org/Tutorial.html



More information about the ENet-discuss mailing list