Well, chat messages still need some binary data, otherwise you have no idea who is sending messages to whom or you will only be able to support a "general chat" protocol. So at the very least you'd need a few bytes to define the channel that's being updated (e.g., General and "Team" like Valve's Source Engine games and mods).<br>
<br>After that you can just copy the bytes after that bit of binary data, something like, knowing your first x bytes are binary, instead of using std::string my_string ((char*)packet->data, packet->dataLength);,<br>
use std::string my_string (((char*)packet->data) + x, packet->dataLength - x);<br><br><div class="gmail_quote">On Mon, Mar 28, 2011 at 4:59 PM, ingmar wirths <span dir="ltr"><<a href="mailto:ingmania@googlemail.com">ingmania@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Thanks for your answers.<br>
I thought there was an easier solution and i was just doing something stupid.<br>
<br>
Nuno: Of course, i do not embed my game data into strings. I was just using<br>
this for chat messages. My idea was to send chat messages on a dedicated<br>
channel reliably, and pass them around in my application as strings.<br>
<br>
Maybe this approach isn't that sound? How have you guys implemented chatting?<br>
<br>
Cheers,<br>
ingmar<br>
<br>
2011/3/28 Nuno Silva <<a href="mailto:little.coding.fox@gmail.com">little.coding.fox@gmail.com</a>>:<br>
<div><div></div><div class="h5">> Just as a follow up to my previous post, you should never use text-based<br>
> packets, especially on UDP, unless you're going for a HTTP-esque protocol<br>
> where everything is pretty much text. The reason for this is that you can<br>
> always encode pretty much anything into binary, which becomes much smaller<br>
> than anything text.<br>
><br>
> As an example, let's say you want to tell a game server that the player with<br>
> ID 123 is going to teleport to gate 567. Originally, as text, it could go<br>
> like "Teleport Player:123 Gate:567". In binary, it could fit into about 12<br>
> bytes or less, vs the text version that takes 27 bytes.<br>
><br>
> The reason UDP should always use binary packets is mainly what i just said<br>
> but also because UDP as a protocol is unreliable, even if Enet has reliable<br>
> packets. That means that if you send huge packets (like 128KB or so), it'll<br>
> almost never reach its destination unless it is really close by.<br>
><br>
> On Mon, Mar 28, 2011 at 4:33 PM, Daniel Aquino <<a href="mailto:mr.danielaquino@gmail.com">mr.danielaquino@gmail.com</a>><br>
> wrote:<br>
>><br>
>> A quick google search gave this link where the last post sounds like it<br>
>> might be your answer:<br>
>><br>
>> <a href="http://www.codeguru.com/forum/showthread.php?t=231155" target="_blank">http://www.codeguru.com/forum/showthread.php?t=231155</a><br>
>><br>
>> But that's really a c++ question not ENet.<br>
>><br>
>><br>
>><br>
>> On Mon, Mar 28, 2011 at 11:26 AM, ingmar wirths <<a href="mailto:ingmania@googlemail.com">ingmania@googlemail.com</a>><br>
>> wrote:<br>
>>><br>
>>> Hi,<br>
>>><br>
>>> i'm getting a little frustrated trying to put the content of a packet<br>
>>> into a string.<br>
>>> What i simply want to do is something like:<br>
>>><br>
>>> std::string my_string (packet->data, packet->dataLength);<br>
>>><br>
>>> This doesn't compile however. I kind of get the idea why not, fiddled<br>
>>> around a little,<br>
>>> but could'nt get it working.<br>
>>><br>
>>> I guess someone did this before, any ideas?<br>
>>><br>
>>> Thanks,<br>
>>> ingmar<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>
>><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>
><br>
><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>
><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>
</div></div></blockquote></div><br>