[ENet-discuss] Not getting any event on my server
Lee Salzman
lsalzman1 at cox.net
Tue Apr 18 21:36:33 PDT 2006
Nope, you only have to destroy packets that you get from RECEIVE events.
Lee
Wai Wu wrote:
> You are absolutely right. After a few hours, I figured that out. Once I
> put in servicing on the client side, it works great. Another question.
> After I send a packet with enet_peer_send, do I have to do a
> enet_packet_destroy?
>
> -----Original Message-----
> From: enet-discuss-bounces at cubik.org
> [mailto:enet-discuss-bounces at cubik.org] On Behalf Of Lee Salzman
> Sent: Tuesday, April 18, 2006 6:28 PM
> To: Discussion of the ENet library
> Subject: Re: [ENet-discuss] Not getting any event on my server
>
> My guess is you are not servicing the client after you get the connect
> event. The connection sequence from a protocol/event standpoint is as
> follows:
>
> Client sends CONNECT to Server.
> Server sends VERIFY_CONNECT to Client on receipt of CONNECT.
> Client generates CONNECT event (your problem likely occurs here) and
> then sends ACKNOWLEDGE on receipt of VERIFY_CONNECT.
> Server generates CONNECT event on receipt of ACKNOWLEDGE.
>
> So the client needs to continue running ENet even after the CONNECT
> event is generated client-side, or else the hand-shake will not be
> completed.
>
> Lee
>
> Wai Wu wrote:
>
>>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;
>>}
>>
>>
>>----------------------------------------------------------------------
>>--
>>
More information about the ENet-discuss
mailing list