[ENet-discuss] Connectionless? Reconnect?

Lee Salzman lsalzman1 at cox.net
Fri Jul 1 18:11:16 PDT 2005


UDP is connectionless, but ENet is NOT. ENet is basically an entirely
different protocol running over UDP. It differs hugely from many other 
"networking" libraries that are nothing more than socket wrappers, which 
ENet is, again, not. There is a "Features and Architecture" page linked 
from the main site which you should really read before attempting to use 
it.

Peers are necessary for talking to multiple clients, servers, or, dare I 
say it, peers. The "data" field of each field persists indefinitely, or 
otherwise stated, ENet will NEVER change its value. It is provided so 
that you may associate whatever connection data you want with the peer 
(like a connection object or some such).

And, quite simply, the ENET_EVENT_TYPE_DISCONNECT event is sent when a 
peer is disconnected. Was this not straight-forwardly enough presented 
in the documentation?

Now, maybe I'm a little dense here, but is there any point in an ENet 
wrapper? ENet's interface is as minimal as it gets for the use it needs 
to support. I can't imagine how simplifying it even further would 
preserve the utility of the library. You create a host, connect to a 
peer, send/receive packets through the peer, and wait for events. Any 
less than that and you just end up with TCP again.

Lee

Darrell Bircsak wrote:
> 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