[ENet-discuss] Waiting for host.

Jay Sprenkle jsprenkle at gmail.com
Mon Jan 3 17:42:28 PST 2011


Try moving the label "TRY_TO_CONNECT:"  before the call to
enet_host_connect()

I would say your English is pretty good. You might say the "host is running"
instead of the "host is raised".
This means the program that is the host has been started.


2011/1/3 Вячеслав Блинников <slavmfm at gmail.com>

> Hello. I need client permanently trying to connect to me (host) while host
> will not be raised and accept a connection. So, the following code,
> presumably, trying to connect each 5 seconds:
>
>     const char* url    = "localhost";
>>     const int port    = 1301;
>>
>>     ENetAddress address;
>>     /* Connect to url:port. */
>>     enet_address_set_host(&address, url);
>>     address.port    = port;
>>
>>     /* Initiate the connection, allocating the one channel. */
>>     ENetPeer* peer    = enet_host_connect(client, &address, 1, 0);
>>     if(peer == 0l)
>>     {
>>         printf("No available peers for initiating an ENet connection.\n");
>>         return 0;
>>     }
>>
>>     ENetEvent event;
>>
>> TRY_TO_CONNECT:
>>
>>     /* 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)
>>     {
>>         printf("Connection to %s:%d succeeded.\n", url, port);
>>     }
>>     else
>>     {
>>         /* Either the 5 seconds are up or a disconnect event was */
>>         /* received. Reset the peer in the event the 5 seconds   */
>>         /* had run out without any significant event.            */
>>         //enet_peer_reset (peer);
>>
>>         printf("Connection to %s:%d failed. Trying again...\n", url,
>> port);
>>
>>         goto TRY_TO_CONNECT;
>>     }
>>
>
> When host is already raised (is it right word in English?) before client
> try to connect - everything works fine, but when I first start the client
> and after several seconds start the server - client will never connect to
> host (will try each 5 seconds but unsuccessfully). What's the problem? Must
> I recreate a peer each time I try to reconnect? If it is so - how can I
> delete previous peer - there is no "enet_peer_destroy()" function.
> The same question: how to reconnect to the server when disconnection
> happened?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110103/e72d6fbb/attachment.html>


More information about the ENet-discuss mailing list