[ENet-discuss] Connectionless? Reconnect?

Darrell Bircsak dbircsak at gmail.com
Fri Jul 1 11:42:10 PDT 2005


Am I correct in thinking UDP is connectionless?  The server takes in
packets from anyone?  Why in ENet do we need to host_connect?  Why do
we need to have an ENetPeer saved outside the host struct?

peer = enet_host_connect(client, &address, 2);

When do we ever use the peer after connecting?  In order to send,
right?  But can't you just do this?

enet_peer_send(host->peers[0], 0, packet);

In other words I am using the peers array in ENetHost struct.

I was also hopeing someone could explain....how we know when we've
lost connection to a server and a good way to reconnect?  Do I do this
by looking at some ENetPeerState?  Does anyone have a code example of
this?  I don't even understand how you can "loose connection" with a
connectionless protocol.

I'm also not understanding the point of event.peer->data....

        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_DISCONNECT:
            printf ("%s disconected.\n", event.peer -> data);

            /* Reset the peer's client information. */

            event.peer -> data = NULL;
        }

Why do we need to do anything with event.peer->data?  Isn't this a bad
place to keep client information as it will just be overwritten the
next time we check for an event (enet_host_service)?  In this great
ENet Wrapper code I found on the net.... they tell who a peer is by
checking the event.peer->incomingPeerID.

		case ENET_EVENT_TYPE_RECEIVE:
			sndData.sData = (char*)m_enEvent.packet->data;
			sndData.iID = m_enEvent.peer->incomingPeerID;
			sndData.iEvent = ENET_EVENT_TYPE_RECEIVE;
			enet_packet_destroy(m_enEvent.packet);
			return sndData;

Anyways, thanks for this great library!!  I just wish there were some
more examples out there!

Darrell Bircsak

P.S. I found the ENet Wrapper here http://programs.geekstreak.com/?id=149
I also found an example of someone using ENet here http://die.sourceforge.net/
Know of any other ENet examples I can look at?



More information about the ENet-discuss mailing list