[ENet-discuss] Question: making outgoing connections

Matthew Hart mambazo at gmail.com
Fri Dec 11 19:28:29 PST 2009


The host doesn't connect to anything initially.

It simply sets itself to listen on a port for incoming traffic.

When it finds some traffic coming it, it triggers an event (which is read
from the event data of the enet_host_service function)

If that event data states it is a *ENET_EVENT_TYPE_CONNECT* packet, then if
this is a new host, it will add to the newly connected peer to the peer
pointer array of the host. Likewise, once a client has connected to a host,
its peer will point to the server you connected to. Sending any packets to
the clients peer will reach the server, and sending an packets to any of the
peers pointer array of the server will reach the one or more of the clients,
depending on who you send it to and whether you broadcast it or not.

If you have any questions, give me a shout at: mambazo at gmail.com

Cheers,
Matt

On Fri, Dec 11, 2009 at 6:57 PM, Jay Sprenkle <jsprenkle at gmail.com> wrote:

> Good afternoon,
> I'm interested in using enet for a project.
>
> I want to make a connection to a server.
> So far I have code to create a host and make an outgoing connection:
>
>       client = enet_host_create(
>          NULL /* create a client host */,
>          1 /* only allow 1 outgoing connection */,
>          57600 / 8 /* 56K modem with 56 Kbps downstream bandwidth */,
>          14400 / 8 /* 56K modem with 14 Kbps upstream bandwidth */
>          );
>       if (client == NULL)
>          throw new std::exception;
>
>       // try to connect to the patch server
>       enet_address_set_host( &address, "localhost" );
>       address.port = 3337;
>       peer = enet_host_connect( client, &address, 1 );
>
> Now I have a enet peer object. When I want to send to the server I do this:
>
>       ENetPacket* packet = enet_packet_create( msg, size, 0 );
>
>       /* Send the packet to the peer over channel id 0. */
>       /* One could also broadcast the packet by         */
>       /* enet_host_broadcast (host, 0, packet);         */
>       enet_peer_send( peer, 0, packet );
>
>       /* One could just use enet_host_service() instead. */
>       enet_host_flush( client );
>
>
> I notice the host flush command looks at the peers member of the host
> structure but how does the peer I created using enet_host_connect() get into
> the peers array of the host struct?
>
> Thanks!
>
>
>
> --
> Cause united breaks guitars
> http://www.youtube.com/watch?v=5YGc4zOqozo
>
>
> _______________________________________________
> 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/20091212/1084d092/attachment.htm>


More information about the ENet-discuss mailing list