Howto set character encoding in actionscript 3 socket connections?

荒凉一梦 提交于 2019-12-11 20:36:31

问题


After asking "Do certain characters take more bytes than others?", I figured out that I'd need to set the character encoding set when receiving and sending data with a socket connection in Actionscript / Flex 3.

Now I've been trying to find out how to do this, however there doesn't seem to be such property available. Is there any special way of doing this?


回答1:


The flash.net.Socket class is a binary input/output class. You do not specify the encoding for the socket itself because you have low-level access to the data in the socket.

What you're looking for is the Socket::readMultiByte method for reading strings from different character sets.

public function readMultiByte(length:uint, charSet:String):String

Likewise, use Socket::writeMultiByte for writing strings from a specific character set.

public function writeMultiByte(value:String, charSet:String):void



回答2:


As far as I know, Flash supports only Unicode... though there is the option to use the OS's code page with System.useCodePage. But it will depend on the user's OS and language, and is not recommended unless you know exactly what you are doing.

As for using less bytes per character, I understand that alphanumeric characters use only one byte in UTF-8 .

Cheers...



来源:https://stackoverflow.com/questions/1068315/howto-set-character-encoding-in-actionscript-3-socket-connections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!