[ENet-discuss] enet_host_service() never returns > 0.
Nuno Silva
little.coding.fox at gmail.com
Mon Jul 4 00:34:20 PDT 2011
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\n");
> break;
> case ENET_EVENT_TYPE_RECEIVE:
> printf("receive\n");
> break;
> case ENET_EVENT_TYPE_DISCONNECT:
> printf("disconnect\n");
> break;
> default:
> break;
> }
> }
>
> printf("Tick tock.\n");
> }
> =====================================================================
>
> 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.\n");
> 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\n");
> return 0;
> }
>
> if (enet_host_service(client, &event, 5000) > 0 &&
> event.type == ENET_EVENT_TYPE_CONNECT) {
>
> printf("Connection to %s succeeded.\n", HOST);
> } else {
> enet_peer_reset(peer);
> printf("Could not connect to %s.\n", 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110704/d6327ece/attachment.html>
More information about the ENet-discuss
mailing list