[ENet-discuss] Problem partailly solved
ingmar wirths
ingmania at googlemail.com
Wed Mar 2 06:03:22 PST 2011
@Nuno:
enum elements are ints, right? I think you can't change this.
Thus you have to append 4 bytes to each packet.
Would'nt it be more efficient to use chars (supposing you don't
have more than 256 different package types)? And even if, you
could still use two chars (or a short) instead of 4 bytes.
What is your opinion on this?
2011/2/28 Nuno Silva <little.coding.fox at gmail.com>:
> First of all you should have an enumeration (enum) of all the packet types
> you can get. Don't use strings, those are too slow and may cause plenty of
> performance issues.
>
> Secondly, you can't just convert the data to string and delete the packet,
> since the data in the string will be deleted at the same time. At most you
> should copy the string, but like i said, you should use enumerations
> instead.
> Finally, you could always use a reference-to-Custom-Packet-class in your
> function. Something like this:
>
> class MyPacket
> {
> friend class HostUpdate;
> private:
> std::vector<unsigned char> data;
> unsigned short type;
> public:
> MyPacket() : type(MAX_PACKET_TYPE);
> int readInt();
> char readChar();
> std::string readString();
> <...>
> }
>
> unsigned short UpdateHost(MyPacket &packet) { <update and copy Packet Data
> to packet> }
>
> On Mon, Feb 28, 2011 at 5:01 PM, Alexaroth <alex_prislopeanu at yahoo.com>
> wrote:
>>
>> Indeed it does not send any data... Now I have another issue:
>>
>>
>>
>> How can I make a function like
>>
>> char* updateHost()
>> {string* b;
>> while (enet_host_service (server, & event, 100) > 0)
>> { switch (event.type)
>> { case ENET_EVENT_TYPE_RECEIVE:
>>
>> b=reinterpret_cast<char*>(event.packet->data);
>>
>> enet_packet_destroy (event.packet);
>> return b;
>> break;
>> }}}
>> I need to call from the main program the function like this:
>> if (updateHost()=="connected")
>> {cout>> Client connected !}
>>
>> I practically want to return whatever packet a client/server sends me...
>>
>>
>>
>> ________________________________
>> From: Ruud van Gaal <ruud at racer.nl>
>> To: Discussion of the ENet library <enet-discuss at cubik.org>
>> Sent: Monday, February 28, 2011 4:23 PM
>> Subject: Re: [ENet-discuss] Problem partailly solved
>>
>> No packet is being sent indeed.
>> The peer->data is a local pointer that only 'lives' at the computer that
>> defines it. Nothing is send; you need packets for that. It's just to
>> associate computer-local data with the peer (a peer is a computer, not a
>> packet).
>>
>> Ruud
>>
>> On Mon, Feb 28, 2011 at 2:10 PM, Nuno Silva <little.coding.fox at gmail.com>
>> wrote:
>>
>> There's no packet size for peer data (at least from what the docs tell me
>> about the _ENetPeer struct), since he's probably not sending a packet. He's
>> just setting the peer's data to the name, not a packet's data.
>>
>> On Mon, Feb 28, 2011 at 12:55 PM, Jay Sprenkle <jsprenkle at gmail.com>
>> wrote:
>>
>> 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;
>>
>>
>>
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>
>>
>>
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>
>>
>>
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>
>>
>>
>>
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>
>
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
>
More information about the ENet-discuss
mailing list