[ENet-discuss] enet_host_service() never returns > 0.
Mike Diehl
mdiehl at diehlnet.com
Mon Jul 4 00:49:54 PDT 2011
I hacked in a quick event loop, and sure enough, it works! Thank you.
"Nuno Silva" <little.coding.fox at gmail.com> wrote:
> You need to have a similar loop like the server in order for the client to
> receive the packet. enet_host_service should be called often since that's
> the only way for either the client or the server to update.
>
> On Mon, Jul 4, 2011 at 7:37 AM, Mike Diehl <mdiehl at diehlnet.com> wrote:
>
>> I'm trying to write a simple demonstration program with enet 1.3.3. The
>> demo is mostly based on the example code snippets from the enet website,
so
>> it should have been fairly simple. ;^)
>>
>> The client claims to have connected successfully. A tcpdump indicates
that
>> the client sent a packet, and the server replied a few times. The server
>> never dispatches the CONNECT event.
>>
>> The applicable server code is:
>> =====================================================================
>> while (1) {
>> while (enet_host_service(server, &event, 5000) > 0) {
>> switch (event.type) {
>> case ENET_EVENT_TYPE_CONNECT:
>> printf("connect");
>> break;
>> case ENET_EVENT_TYPE_RECEIVE:
>> printf("receive");
>> break;
>> case ENET_EVENT_TYPE_DISCONNECT:
>> printf("disconnect");
>> break;
>> default:
>> break;
>> }
>> }
>>
>> printf("Tick tock.");
>> }
>> =====================================================================
>>
>> All it prints is Tick Tock, over and over again.
>>
>> The client code is fairly straightforward:
>> =====================================================================
>> client = enet_host_create(NULL, 1, 2, 5760/8, 1440/8);
>>
>> if (client == NULL) {
>> printf("Could not create client.");
>> return 0;
>> }
>>
>> enet_address_set_host(&address, HOST);
>> address.port = PORT;
>>
>> peer = enet_host_connect(client, &address, 2, 0);
>>
>> if (peer == NULL) {
>> printf("Could not connect to server");
>> return 0;
>> }
>>
>> if (enet_host_service(client, &event, 5000) > 0 &&
>> event.type == ENET_EVENT_TYPE_CONNECT) {
>>
>> printf("Connection to %s succeeded.", HOST);
>> } else {
>> enet_peer_reset(peer);
>> printf("Could not connect to %s.", HOST);
>> return 0;
>> }
>> =====================================================================
>> This code indicates that it was able to connect to the server.
>> What am I missing? TIA.
>> ------------------------------
>>
>> Take care and have fun,
>> Mike Diehl.
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>
>>
>
--------------------------------
_______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
--
Take care and have fun,
Mike Diehl.
More information about the ENet-discuss
mailing list