使用 IdTCPClient1 和 IdTCPServer1 发送接收 16 进制数据的问题
我从网上找了些例子,测试结果都不太对,请教一下哪里有问题发送数据如下
procedure Tmainfrm.Button1Click(Sender: TObject);
var
scmdatabyte: array of byte;
scmData: String;
i:Integer;
begin
scmData:='1A1B1C1D1E1F10121314';
SetLength(scmdatabyte, Trunc(Length(scmdata) / 2));
for i:= 0 to Trunc(Length(scmdata)/2)-1 do
begin
scmdatabyte[i] := StrToInt('$' + scmdata[2 * i+1] + scmdata[2 * i + 2]);
end;
IdTCPClient1.WriteBuffer(scmdatabyte,10);
end;
接收
procedure Tmainfrm.IdTCPServer1Execute(AThread: TIdPeerThread);
var
i,ilen,count: integer;
buf: array of byte;
temp:string;
begin
try
temp:='';
count:=AThread.Connection.ReadFromStack;
if count<>0 then
begin
setlength(buf, count);
AThread.Connection.ReadBuffer(buf[0], count);
end;
for i:=0 to count-1 do
temp:=temp+inttohex(buf[i],2);
Memo1.Lines.Add(temp);
finally
end;
end;
接收到的数并不是我发出的数据