They're probably being set up in a queue waiting for the next enet_host_service to be sent/processed if you're sending packets. Nothing happens if you never call enet_host_service, which is why you should call it regularly.<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;">
It's steal unclear. In case "enet_host_service()" returns on any event<br>
- so it will be perfect if I will set the "infinite" time for it<br>
because I do not need to do something when no messages occur. Other<br>
libraries with suct interface behave as I said ("windows messages",<br>
for example).<br>
What is happening with the messages which appear when<br>
enet_host_service() is not run (between it's calls)?<br>
<br>
5 ÎÏÑÂÒÑ 2010šÇ. 18:01 ÐÏÌØÚÏ×ÁÔÅÌØ Nuno Silva<br>
<div><div></div><div class="h5"><<a href="mailto:little.coding.fox@gmail.com">little.coding.fox@gmail.com</a>> ÎÁÐÉÓÁÌ:<br>
> As far as i know ENet isnt thread-safe, so it's probably a bad idea to do<br>
> that.<br>
> enet_host_service will wait for events, until a certain timeout, or until an<br>
> event is triggered. So, if you dont want any lag on your events, you should<br>
> limit the timeout to something small like e.g., 25-50, which is very little<br>
> compared to 1000.<br>
><br>
> 2010/11/5 ÷ÑÞÅÓÌÁ× âÌÉÎÎÉËÏ× <<a href="mailto:slavmfm@gmail.com">slavmfm@gmail.com</a>><br>
>><br>
>> Thank you very much! It works now!<br>
>> Is it right calling that function in the separate thread? Like that:<br>
>><br>
>> void* ENetHostService(void* client)<br>
>> {<br>
>> š š š šENetHost* castClient š š= (ENetHost*)client;<br>
>> š š š šENetEvent event;<br>
>><br>
>> ENET_HOST_SERVICE:<br>
>> š š š šenet_host_service(castClient, &event, 1000);<br>
>> š š š šgoto ENET_HOST_SERVICE;<br>
>> }<br>
>><br>
>> But I think I have some lags in messages sending - what is the point<br>
>> in third param to enet_host_service()? Does not this function returns<br>
>> (do it's job (message sending in our case)) just in moment when<br>
>> enet_peer_send() where called? Or it will wait 1000 milliseconds<br>
>> anyway?<br>
>><br>
>> So, am I right in the whole structure (calling enet_host_service()<br>
>> permanently in different thread) or there are better ways? And is it<br>
>> alrignt thet I do not use mutexes when call enet_peer_send()?<br>
>><br>
>> 5 ÎÏÑÂÒÑ 2010šÇ. 17:10 ÐÏÌØÚÏ×ÁÔÅÌØ Nuno Silva<br>
>> <<a href="mailto:little.coding.fox@gmail.com">little.coding.fox@gmail.com</a>> ÎÁÐÉÓÁÌ:<br>
>> > Hey there.<br>
>> > On your while(true) on the client you must also call enet_host_service<br>
>> > 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",<br>
>> >> 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 /<br>
>> >> 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>
>> >> ==<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],<br>
>> >> 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>
>> _______________________________________________<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>
_______________________________________________<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>