[ENet-discuss] Question: making outgoing connections

Jay Sprenkle jsprenkle at gmail.com
Fri Dec 11 10:57:39 PST 2009


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20091211/9b0bc3b4/attachment.htm>


More information about the ENet-discuss mailing list