[ENet-discuss] Waiting for host.
Вячеслав Блинников
slavmfm at gmail.com
Mon Jan 3 14:25:53 PST 2011
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/20110104/ab8913b5/attachment.html>
More information about the ENet-discuss
mailing list