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.<br><br>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.<br>
Finally, you could always use a reference-to-Custom-Packet-class in your function. Something like this:<br><br>class MyPacket<br>{<br>friend class HostUpdate;<br>private:<br>    std::vector<unsigned char> data;<br>    unsigned short type;<br>
public:<br>    MyPacket() : type(MAX_PACKET_TYPE);<br>    int readInt();<br>    char readChar();<br>    std::string readString();<br>    <...><br>}<br><br>unsigned short UpdateHost(MyPacket &packet) { <update and copy Packet Data to packet> }<br>
<br><div class="gmail_quote">On Mon, Feb 28, 2011 at 5:01 PM, Alexaroth <span dir="ltr"><<a href="mailto:alex_prislopeanu@yahoo.com">alex_prislopeanu@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div style="color:#000;font-size:14pt"><font face="comic sans ms">Indeed it does not send any data... Now I have another issue:<br><br><br><br>How can I make a function like <br><br>char* updateHost()<br>{string* b;<div class="im">
<br>while (enet_host_service (server, & event, 100) > 0)<br>    {   switch (event.type)<br></div>        {         case ENET_EVENT_TYPE_RECEIVE:<br>          <br>              b=reinterpret_cast<char*>(event.packet->data);<br>
<br>             enet_packet_destroy (event.packet);<br>             return b;<br>           
  break;<br>}}}<br>I need to call from the main program the function like this:<br>if (updateHost()=="connected")<br>{cout>> Client connected !}<br><br>I practically want to return whatever packet a client/server sends me... <br>
<br></font><div><br></div><div><br></div><div style="font-family:times new roman, new york, times, serif;font-size:14pt"><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><font face="Arial" size="2"><hr size="1">
<b><span style="font-weight:bold">From:</span></b> Ruud van Gaal <<a href="mailto:ruud@racer.nl" target="_blank">ruud@racer.nl</a>><br><b><span style="font-weight:bold">To:</span></b> Discussion of the ENet library <<a href="mailto:enet-discuss@cubik.org" target="_blank">enet-discuss@cubik.org</a>><br>
<b><span style="font-weight:bold">Sent:</span></b> Monday, February 28, 2011 4:23 PM<br><b><span style="font-weight:bold">Subject:</span></b> Re: [ENet-discuss] Problem partailly solved<br></font><div><div></div><div class="h5">
<br> 
<div>No packet is being sent indeed.<br>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).<br>

<br>Ruud<br><br><div>On Mon, Feb 28, 2011 at 2:10 PM, Nuno Silva <span dir="ltr"><<a rel="nofollow" href="mailto:little.coding.fox@gmail.com" target="_blank">little.coding.fox@gmail.com</a>></span> wrote:<br><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">

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.<br>


<br><div><div><div></div><div>On Mon, Feb 28, 2011 at 12:55 PM, Jay Sprenkle <span dir="ltr"><<a rel="nofollow" href="mailto:jsprenkle@gmail.com" target="_blank">jsprenkle@gmail.com</a>></span> wrote:<br>
</div></div><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><div><div></div><div>
Some quick comments. See below:<br><br><div><div>On Mon, Feb 28, 2011 at 5:32 AM, Alexaroth <span dir="ltr"><<a rel="nofollow" href="mailto:alex_prislopeanu@yahoo.com" target="_blank">alex_prislopeanu@yahoo.com</a>></span> wrote:<br>



<blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><div><div style="color:rgb(0, 0, 0);font-size:14pt"><div>Well I kinda understand how things work... the thing is this</div>



<div><br></div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">I have some client code:</div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">



<br></div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">peer = enet_host_connect (client, & address, 2, 0);<br>


</div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">name = 
 player.getname();    //this returns a string from inside a class member<br>peer->data = (void*)name.c_str();  I am making the peer data the name of the player</div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">



<br></div></div></div></blockquote></div><div><br>I assume you set the packet size to the size of the name string ?<br><br><br> </div><div><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">



<div><div style="color:rgb(0, 0, 0);font-size:14pt"><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal"></div>
<div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">

<br></div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">On the server end: <br></div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">



<br></div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">ENetPeer *peer2[2];</div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">



<br></div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">while (enet_host_service (server, & event, 100) > 0)<br>



    {   switch (event.type)<br>        {</div><div style="color:rgb(0, 0, 0);font-size:18.6667px;font-family:times new roman, new york, times, serif;background-color:transparent;font-style:normal">        case ENET_EVENT_TYPE_CONNECT:              <br>



<br>            peer2[1] =
 event.peer;    <br>            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<br>            name=(char*)peer->data;<br>



<br></div></div></div></blockquote></div><div><br>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.<br>



<br>Shouldn't this:<br>name=(char*)peer->data;<br><br>be this:<br>name=(char*)peer2[1]->data;<br><br></div></div><br>
<br></div></div>_______________________________________________<br>
ENet-discuss mailing list<br>
<a rel="nofollow" href="mailto:ENet-discuss@cubik.org" target="_blank">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
ENet-discuss mailing list<br>
<a rel="nofollow" href="mailto:ENet-discuss@cubik.org" target="_blank">ENet-discuss@cubik.org</a><br>
<a rel="nofollow" href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br></blockquote></div><br>
</div><br>_______________________________________________<br>ENet-discuss mailing list<br><a href="mailto:ENet-discuss@cubik.org" target="_blank">ENet-discuss@cubik.org</a><br><a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br><br></div></div></div></div></div><br>







      </div><br>_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br></blockquote></div><br>