Try moving the label "TRY_TO_CONNECT:" before the call to enet_host_connect()<br><br>I would say your English is pretty good. You might say the "host is running" instead of the "host is raised".<br>
This means the program that is the host has been started.<br><br><br><div class="gmail_quote">2011/1/3 Вячеслав Блинников <span dir="ltr"><<a href="mailto:slavmfm@gmail.com">slavmfm@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
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:<br><br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">
const char* url = "localhost";<br> const int port = 1301;<br> <br> ENetAddress address;<br> /* Connect to url:port. */<br> enet_address_set_host(&address, url);<br> address.port = port;<br>
<br> /* Initiate the connection, allocating the one channel. */<br> ENetPeer* peer = enet_host_connect(client, &address, 1, 0);<br> if(peer == 0l)<br> {<br> printf("No available peers for initiating an ENet connection.\n");<br>
return 0;<br> }<br> <br> ENetEvent event;<br><br>TRY_TO_CONNECT:<br><br> /* Wait up to 5 seconds for the connection attempt to succeed. */<br> if (enet_host_service (client, & event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT)<br>
{<br> printf("Connection to %s:%d succeeded.\n", url, port);<br> }<br> else<br> {<br> /* Either the 5 seconds are up or a disconnect event was */<br> /* received. Reset the peer in the event the 5 seconds */<br>
/* had run out without any significant event. */<br> //enet_peer_reset (peer);<br> <br> printf("Connection to %s:%d failed. Trying again...\n", url, port);<br><br> goto TRY_TO_CONNECT;<br>
}<br></blockquote><div><br>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.<br>
The same question: how to reconnect to the server when disconnection happened?<br></div>
<br>
</blockquote></div><br>