UTF-8
UTF-8是UNICODE的一种变长字符编码又称万国码,由Ken Thompson于1992年创建。现在已经标准化为RFC 3629。UTF-8用1到6个字节编码UNICODE字符。用在网页上可以同一页面显示中文简体繁体及其它语言(如日文,韩文)。
使用UTF-8的好处是现在一些手机平台都是使用UTF-8,另外在一些嵌入式平台,如果不支持中文,只支持英文,可以不转换,UTF-8就可以识别。
DELPHI默认支持的编码是ANSI,为了支持UTF-8,需要转换下,为了编程简便性,我们只在发包和解包的地方进行UTF-8转换。
发包:
function TBaseClientSocket.ControlCommand(const ACommand: string;
ARequest, AResponse: TStrings; const AData: string): Boolean;
var
slBuff: TStringList;
dwPacketLen, dwCommandLen, dwCode: Cardinal;
sBuff: string;
utf8Command, utf8Data: UTF8String;
begin
try
slBuff := TStringList.Create;
try
FClient.ReadTimeout := FTimeOutMS;
FClient.MaxLineLength := 1024 * 1024 * 1024;
slBuff.Add('[' + CSRequest + ']');
slBuff.Add(CSCommand + CSEqualSign + ACommand);