[ENet-discuss] Not getting any event on my server

Wai Wu wwu at Calltrol.com
Tue Apr 18 14:38:55 PDT 2006


Hi all,
 
Can some one take a look at my simple testing code? I am not getting any
events at all. I use a simple client code connect to it. The client says
connection is sucessful but there is no event generated on the server.
 
 
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include "enet\enet.h"
 

ENetHost * server;
 
void startserver(int UDPport)
{
 
    ENetAddress address;
 
    /* Bind the server to the default localhost.     */
    /* A specific host address can be specified by   */
    enet_address_set_host (& address, "localhost");
 
    address.host = ENET_HOST_ANY;
    /* Bind the server to port 1234. */
    address.port = UDPport;
 
    server = enet_host_create (& address /* the address to bind the
server host to */, 
                                 32      /* allow up to 32 clients
and/or outgoing connections */,
                                  0      /* assume any amount of
incoming bandwidth */,
                                  0      /* assume any amount of
outgoing bandwidth */);
    if (server == NULL)
    {
        fprintf (stderr, 
                 "An error occurred while trying to create an ENet
server host.\n");
        exit (EXIT_FAILURE);
    }
 
}
 
void stopserver()
{
    enet_host_destroy(server);
}
 
 
 
void evtThread(void *p)
{
    ENetEvent event;
    
    /* Wait up to 1000 milliseconds for an event. */
 int rc = enet_host_service (server, & event, 1000);
    while (rc >= 0)
    {
  cprintf("Event rc %d\r\n", rc);
  if (rc > 0)
  {
   switch (event.type)
   {
   case ENET_EVENT_TYPE_CONNECT:
    printf ("A new client connected from %x:%u.\n", 
      event.peer -> address.host,
      event.peer -> address.port);
 
    /* Store any relevant client information here. */
    event.peer -> data = "Client information";
 
    break;
 
   case ENET_EVENT_TYPE_RECEIVE:
     printf ("A packet of length %u containing %s was received from %s
on channel %u.\n",
      event.packet -> dataLength,
      event.packet -> data,
      event.peer -> data,
      event.channelID);
 
     /* Clean up the packet now that we're done using it. */
    enet_packet_destroy (event.packet);
            
    break;
           
   case ENET_EVENT_TYPE_DISCONNECT:
    printf ("%s disconected.\n", event.peer -> data);
 
    /* Reset the peer's client information. */
 
    event.peer -> data = NULL;
   }
  }
  rc = enet_host_service (server, & event, 1000);
    }
}
 
int main (int argc, char * argv[]) 
{
    if (enet_initialize () != 0)
    {
        fprintf (stderr, "An error occurred while initializing
ENet.\n");
        return EXIT_FAILURE;
    }
    atexit (enet_deinitialize);
 
 startserver(atoi(argv[1]));
 _beginthread(evtThread, 300, NULL);
 getch();
 stopserver();
 return 0;
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cubik.org/pipermail/enet-discuss/attachments/20060418/f949b00e/attachment.htm 


More information about the ENet-discuss mailing list