Well, it depends, if you're not getting any events it's normal that enet_host_service blocks for 15ms. Are you trying to say that ENet is "slow"? Because 7.5ms of lag between checking events and sending a message isnt really slow. ENet has been used in various projects with great success, surely those 7.5ms arent time critical for your app? If they are, then you might consider getting a different network library.<br>
<br><div class="gmail_quote">2010/11/5 ÷ÑÞÅÓÌÁ× âÌÉÎÎÉËÏ× <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;">
I reduced the timeout (third param of "enet_host_service()") to 15<br>
milliseconds and connection became faster - so it proofs that actually<br>
message (using "enet_peer_send()") will be sent with lag which vary<br>
between 0 and 15 milliseconds - we have 7,5 milliseconds lag! And it's<br>
just in sending.<br>
<br>
5 ÎÏÑÂÒÑ 2010šÇ. 18:17 ÐÏÌØÚÏ×ÁÔÅÌØ ÷ÑÞÅÓÌÁ× âÌÉÎÎÉËÏ×<br>
<<a href="mailto:slavmfm@gmail.com">slavmfm@gmail.com</a>> ÎÁÐÉÓÁÌ:<br>
<div><div></div><div class="h5">> That is strange because previous advice helped me - everything what<br>
> was needed is to call "enet_host_service()" in separate thread (I<br>
> tried to call it between "getchar()" calls but there still was<br>
> disconnections).<br>
> But I definetly feel some lags. Sometimes lags are obvious but<br>
> sometimes it looks like there are no of them - I think it's depends on<br>
> when how close to "enet_host_service()"'s time interval<br>
> "enet_peer_send()" will be called.<br>
><br>
> 2010/11/5 Nicholas J Ingrassellino <<a href="mailto:nick@lifebloodnetworks.com">nick@lifebloodnetworks.com</a>>:<br>
>> The same thing happens to me if the client does nothing (no events to send,<br>
>> ect) even when calling enet_host_service() on a regular basis. I just added<br>
>> an unreliable "ping packet" every once in a while which solved it.<br>
>><br>
>> ________________________________<br>
>><br>
>> Nicholas J Ingrassellino<br>
>> LifebloodNetworks.com || <a href="mailto:nick@lifebloodnetworks.com">nick@lifebloodnetworks.com</a><br>
>><br>
>> "The idea that I can be presented with a problem, set out to logically solve<br>
>> it with the tools at hand, and wind up with a program that could not be<br>
>> legally used because someone else followed the same logical steps some years<br>
>> ago and filed for a patent on it is horrifying."<br>
>> - John Carmack on software patents<br>
>><br>
>> On 11/05/2010 10:10 AM, Nuno Silva wrote:<br>
>><br>
>> Hey there.<br>
>> On your while(true) on the client you must also call enet_host_service in<br>
>> order for the client to keep its connection alive.<br>
>><br>
>> 2010/11/5 ÷ÑÞÅÓÌÁ× âÌÉÎÎÉËÏ× <<a href="mailto:slavmfm@gmail.com">slavmfm@gmail.com</a>><br>
>>><br>
>>> 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>
>>> -><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<br>
>>> 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,<br>
>>> 14400 / 8);<br>
>>> š š š šif(client == 0l)<br>
>>> š š š š{<br>
>>> š š š š š š š šprintf("An error occurred while trying to create an ENet<br>
>>> 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<br>
>>> 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">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>
>><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>
>> _______________________________________________<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>
>><br>
><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>
</div></div></blockquote></div><br>