S
staven
Unregistered / Unconfirmed
GUEST, unregistred user!
最近用ics写了一段通讯的代码,可是发现接收数据的时间比发送数据的时间长。但是数据类荣是完全一样的,不知道怎么回事?
下面是发送和接收端的代码。
发送:
var
newdata: TMemoryStream;
begin
if Connected then
begin
//DisplayConnectStatus(3);
while ConnnectBusy do
begin
Application.ProcessMessages;
if not Connected then
exit;
end;
newdata := TMemoryStream.Create;
newdata.write(head, sizeof(head));
newdata.Write(data[1], length(data));
datanum := newdata.Size;
if Head.RAFalg='R' then ConnnectBusy:=true;
CliSocket.Send(newdata.Memory, newdata.Size);
newdata.Free;
end;
接收:
procedure TcommunicationForm.CliSocketDataAvailable(Sender: TObject;
Error: Word);
begin
with CliSocket do
begin
if Error <> 0 then
DisplayConnectStatus(8,0);
RecvStr := RecvStr + ReceiveStr; //其中recvstr:string
DealReceivedata; //处理数据函数,如果一个完整数据接收完,则会recvstr='' 否则不处理
end;
end;
下面是发送和接收端的代码。
发送:
var
newdata: TMemoryStream;
begin
if Connected then
begin
//DisplayConnectStatus(3);
while ConnnectBusy do
begin
Application.ProcessMessages;
if not Connected then
exit;
end;
newdata := TMemoryStream.Create;
newdata.write(head, sizeof(head));
newdata.Write(data[1], length(data));
datanum := newdata.Size;
if Head.RAFalg='R' then ConnnectBusy:=true;
CliSocket.Send(newdata.Memory, newdata.Size);
newdata.Free;
end;
接收:
procedure TcommunicationForm.CliSocketDataAvailable(Sender: TObject;
Error: Word);
begin
with CliSocket do
begin
if Error <> 0 then
DisplayConnectStatus(8,0);
RecvStr := RecvStr + ReceiveStr; //其中recvstr:string
DealReceivedata; //处理数据函数,如果一个完整数据接收完,则会recvstr='' 否则不处理
end;
end;