Or you could just call enet_ping :D<br>At least AFAIR there's a function named like that.<br><br><div class="gmail_quote">On Fri, Nov 5, 2010 at 2:58 PM, Nicholas J Ingrassellino <span dir="ltr"><<a href="mailto:nick@lifebloodnetworks.com">nick@lifebloodnetworks.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
The same thing happens to me if the client does nothing (no events
to send, ect) even when calling enet_host_service() on a regular
basis. I just added an unreliable "ping packet" every once in a
while which solved it.<br>
<div><br>
<hr style="min-height: 1px;">
<p><span style="font-weight: bold;">Nicholas J Ingrassellino<br>
<a style="text-decoration: none;" href="http://www.lifebloodnetworks.com/" target="_blank">LifebloodNetworks.com</a></span>
|| <a style="text-decoration: none;" href="mailto:nick@lifebloodnetworks.com" target="_blank">nick@lifebloodnetworks.com</a></p>
<p style="font-size: 75%;">"<span style="font-style: italic;">The
idea that I can be presented with a problem, set out to
logically solve it with the tools at hand, and wind up with a
program that could not be legally used because someone else
followed the same logical steps some years ago and filed for a
patent on it is horrifying.</span>"<br>
- <span style="font-weight: bold;">John Carmack</span> on
software patents</p>
</div><div><div></div><div class="h5">
<br>
On 11/05/2010 10:10 AM, Nuno Silva wrote:
<blockquote type="cite">Hey there.<br>
On your while(true) on the client you must also call
enet_host_service in order for the client to keep its connection
alive.<br>
<br>
<div class="gmail_quote">2010/11/5 Вячеслав Блинников <span dir="ltr"><<a href="mailto:slavmfm@gmail.com" target="_blank">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!<br>
<br>
I wrote the base client accordingly the tutorial and the
client which<br>
read inputting through console characters and send it to the
server.<br>
Everything is fine but just first 30 seconds - then happen the<br>
disconnection (message "Client information disconnected"
shown).<br>
What is wrong with my code?<br>
<br>
<br>
<br>
Server code:<br>
<br>
#include <cstdio><br>
#include "enet\enet.h"<br>
int main(int argc, int** argv)<br>
{<br>
if (enet_initialize () != 0)<br>
{<br>
printf ("An error occurred while initializing
ENet.\n");<br>
goto END;<br>
}<br>
ENetAddress address;<br>
address.host = ENET_HOST_ANY;<br>
address.port = 1234;<br>
ENetHost* server = enet_host_create ( & address,
32, 2, 0, 0);<br>
if (server == NULL)<br>
{<br>
printf("An error occurred while trying to create an
ENet<br>
client host.\n");<br>
goto END;<br>
}<br>
ENetEvent event;<br>
WAIT_FOR_AN_EVENT:<br>
enet_host_service(server, &event, 5);<br>
switch (event.type)<br>
{<br>
case ENET_EVENT_TYPE_CONNECT:<br>
printf ("A new client connected from %x:%u.\n",
event.peer -><br>
address.host, event.peer -> address.port);<br>
event.peer -> data = "Client information";<br>
break;<br>
<br>
case ENET_EVENT_TYPE_RECEIVE:<br>
printf ("A packet of length %u was received
from %s on channel %u.<br>
Containings:\n %s", event.packet -> dataLength, event.peer
-> data,<br>
event.channelID, event.packet -> data);<br>
enet_packet_destroy (event.packet);<br>
break;<br>
<br>
case ENET_EVENT_TYPE_DISCONNECT:<br>
printf ("%s disconected.\n", event.peer ->
data);<br>
event.peer -> data = NULL;<br>
break;<br>
<br>
case ENET_EVENT_TYPE_NONE:<br>
break;<br>
}<br>
goto WAIT_FOR_AN_EVENT;<br>
<br>
printf("host halted.\n");<br>
<br>
END:<br>
getchar();<br>
return 0;<br>
}<br>
<br>
<br>
<br>
Client code:<br>
<br>
#include <cstdio><br>
#include "enet\enet.h"<br>
#include <vector><br>
int main(int argc, int** argv)<br>
{<br>
//where reading console data will be stored:<br>
std::vector<char> buffer;<br>
<br>
if (enet_initialize () != 0)<br>
{<br>
printf ("An error occurred while initializing
ENet.\n");<br>
goto END;<br>
}<br>
ENetHost* client = enet_host_create ( NULL, 1,
2, 57600 / 8, 14400 / 8);<br>
if(client == 0l)<br>
{<br>
printf("An error occurred while trying to
create an ENet server host.\n");<br>
goto END;<br>
}<br>
ENetAddress address;<br>
enet_address_set_host(&address, "localhost");<br>
address.port = 1234;<br>
<br>
ENetPeer* peer = enet_host_connect(client,
&address, 2, 0);<br>
if(peer == 0l)<br>
{<br>
printf("No available peers for initiating an
ENet connection.\n");<br>
goto END;<br>
}<br>
<br>
ENetEvent event;<br>
if (enet_host_service (client, & event, 5000) >
0 && event.type ==<br>
ENET_EVENT_TYPE_CONNECT)<br>
{<br>
puts ("Connection to localhost:1234
succeeded.");<br>
}<br>
else<br>
{<br>
enet_peer_reset (peer);<br>
<br>
puts ("Connection to localhost:1234 failed.");<br>
goto END;<br>
}<br>
<br>
printf("Input some data which will be sent to
server...\n");<br>
<br>
INPUT_DATA:<br>
buffer.clear();<br>
while(true)<br>
{<br>
char character = getchar();<br>
buffer.push_back(character);<br>
if(character == '\n')<br>
{<br>
break;<br>
}<br>
}<br>
buffer.push_back('\0');<br>
<br>
ENetPacket * packet =
enet_packet_create(&buffer[0], buffer.size(),<br>
ENET_PACKET_FLAG_RELIABLE);<br>
enet_peer_send (peer, 0, packet);<br>
enet_host_flush(client);<br>
goto INPUT_DATA;<br>
<br>
END:<br>
getchar();<br>
<br>
return 0;<br>
}<br>
_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org" target="_blank">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
</blockquote>
</div>
<br>
<pre><fieldset></fieldset>
_______________________________________________
ENet-discuss mailing list
<a href="mailto:ENet-discuss@cubik.org" target="_blank">ENet-discuss@cubik.org</a>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a>
</pre>
</blockquote>
</div></div></div>
<br>_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br></blockquote></div><br>