[ENet-discuss] Problem partailly solved

Jay Sprenkle jsprenkle at gmail.com
Mon Feb 28 04:55:23 PST 2011


Some quick comments. See below:

On Mon, Feb 28, 2011 at 5:32 AM, Alexaroth <alex_prislopeanu at yahoo.com>wrote:

> Well I kinda understand how things work... the thing is this
>
> I have some client code:
>
> peer = enet_host_connect (client, & address, 2, 0);
> name =  player.getname();    //this returns a string from inside a class
> member
> peer->data = (void*)name.c_str();  I am making the peer data the name of
> the player
>
>
I assume you set the packet size to the size of the name string ?




>
> On the server end:
>
> ENetPeer *peer2[2];
>
> while (enet_host_service (server, & event, 100) > 0)
>     {   switch (event.type)
>         {
>         case ENET_EVENT_TYPE_CONNECT:
>
>             peer2[1] = event.peer;
>             textprintf_ex(screen, font, 10, 200, white,-1,"%s is client
> !",peer2[1]->data);   this is allegro, it just outputs the %s is client on
> screen
>             name=(char*)peer->data;
>
>
You're using a pointer here instead of copying the data from the enet
packet.  Make sure you aren't using deleted data or just losing memory by
not destroying packets.

Shouldn't this:
name=(char*)peer->data;

be this:
name=(char*)peer2[1]->data;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20110228/d3431321/attachment.html>


More information about the ENet-discuss mailing list