On the Android side, at the most basic level, you can use:
byte[] b = String.getBytes("utf-8")
String s = new String(b, "utf-8")
to convert back and forth.
UTF-8 encoding is designed in such a way that it won't interfere with
regular ASCII characters, including special ones that may have meaning in
your protocol, like newlines and linefeeds:
http://en.wikipedia.org/wiki/UTF-8#Description
( an aside: this also makes it possible to detect and correctly decode
UTF-8 text if it's mistakenly specified as having some other encoding...
for the most part, more or less, anyway... )
There are also various stream classes that do the encoding and decoding for
you on the fly:
http://developer.android.com/reference/java/io/InputStreamReader.html
http://developer.android.com/reference/java/io/OutputStreamWriter.html
There must be functions / methods in PHP equivalent to the above (can't be
more specific, haven't used PHP in, like, 10 years).
-- K
2012/6/14 Francisco M. Marzoa Alonso <[email protected]>
> Hi,
>
> I am implementing an standalone client/server protocol to make one of my
> games online capable. One of the problems I have found is that some
> strings passwed between client and server may have characters that must
> be encoded on UTF-8 (like spanish ñ for example).
>
> The first thing I though was using hexadecimal notation for each char,
> so an string like ESPAÑA will be enconded and sent as:
>
> 004500530050004100D10041
>
> But I rather like to avoid this, since it generates an unnecessary
> network load for just one char, and I expect to have hundreds of
> concurrent connections, so it is important to loose all the fat I can...
>
> I have found this altenative notation may be a good alternative:
>
> ESPAU+00D1A
>
> But I did not found where it is documented, also I do not know if
> Android has native functions to handle this, that may be an interesting
> advantage for prefering one notation over another.
>
> Also this one, claimed to be "JavaScript escapes" looks interesting,
> with the same load than the previous one:
>
> ESPA\u00D1A
>
> I am using this online tool for my testings:
>
> http://www.rishida.net/tools/conversion/
>
> Well, bearing in mind that the client will be written in Android, and
> the server in PHP, what you think should be the best option for encoding
> UTF-8 chars during transmission?
>
> Regards,
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en