我用idtcpserver组件接受传入的信息,但是bRecBuffer的信息如果字节比较多(比如184个字节),就会出现数据不准的现象(184个字节总是中间缺少2个字节)。代码如下:
procedure TfrmNetCopyGPRS.IdTCPServer1Execute(AThread: TIdPeerThread);
var
t:string;
ilen:integer;
bRecBuffer : TrecBuffer;
i:integer;
p:pointer;
dataarr:tDataarr;
begin
aThread.Connection.ReadFromStack;
ilen := AThread.Connection.InputBuffer.Size; if ilen<>0 then
begin
//memo1.Lines.Add('刚刚接收了'+inttostr(ilen)+'个数据'); AThread.Connection.ReadBuffer(bRecBuffer,ilen);
UnitGPRSProtocol.ConvertRecBuffer(brecbuffer,dataarr,ilen);
if (bRecBuffer[8]=5) and (bRecBuffer[10]=$20) then
begin
if(UnitGPRSProtocol.CompareCheckCode(dataarr,13)) and
UnitGPRSProtocol.LeaderCharRight(dataarr,13) then AThread.Connection.WriteBuffer(bRecBuffer,13);
addToActiveCenterlist(bRecBuffer[9],AThread);
exit; //退出来
end
else
begin
UnitGPRSProtocol.TreateRetData(iProtocoltype,G_FunctionCode,dataarr,self.edtValue.Text);
end;
end
procedure TfrmNetCopyGPRS.IdTCPServer1Execute(AThread: TIdPeerThread);
var
t:string;
ilen:integer;
bRecBuffer : TrecBuffer;
i:integer;
p:pointer;
dataarr:tDataarr;
begin
aThread.Connection.ReadFromStack;
ilen := AThread.Connection.InputBuffer.Size; if ilen<>0 then
begin
//memo1.Lines.Add('刚刚接收了'+inttostr(ilen)+'个数据'); AThread.Connection.ReadBuffer(bRecBuffer,ilen);
UnitGPRSProtocol.ConvertRecBuffer(brecbuffer,dataarr,ilen);
if (bRecBuffer[8]=5) and (bRecBuffer[10]=$20) then
begin
if(UnitGPRSProtocol.CompareCheckCode(dataarr,13)) and
UnitGPRSProtocol.LeaderCharRight(dataarr,13) then AThread.Connection.WriteBuffer(bRecBuffer,13);
addToActiveCenterlist(bRecBuffer[9],AThread);
exit; //退出来
end
else
begin
UnitGPRSProtocol.TreateRetData(iProtocoltype,G_FunctionCode,dataarr,self.edtValue.Text);
end;
end
解决方案 »
- 请问delphi里的对齐按钮能让它旁边出现一个让人一目了然的对齐图标吗?
- 请问用MSComm控件编写手机发送短信的问题 谢谢!
- 关于"在SQL语句结尾之后找到字符",
- 怎么把1转换成00001?
- help,help,help关于com中关于数组传递
- 这段时间正努力学DELPHI,正想问时才发现分快用光了,各位好心的大虾能帮帮我吗?
- 如何获得报表总页数
- 我要把SQL_server 中数据库导出来,安装到别的机器上,不通过局域网,怎样实现?谢谢大家帮忙!!
- 用tchart得AddXY()画图的疑惑
- 请问在报表里怎样画表格
- 怎么在 DBGrid 中跟踪数据记录
- 在线等:马上给分:相同长度的字符串比较问题
每次都检测当前接收栈的数据量。
另外,如果是简单的字符串传输,完全可以使用WriteLn(字符串+终止符);ReadLn(终止符,等待时间);来传输,更有效。