顺
顺顺
Unregistered / Unconfirmed
GUEST, unregistred user!
代码目标是这样:接收不定长的数据包,解析后根据命令返回结果
在服务端:
idTCPsExecute(AThread: TIdPeerThread);中,我做如下处理
with AThread.Connection do
begin
RevcSize := ReadFromStack(False); //取接收的长度
SetLength (RevcBuff,RevcSize); //分配空间大小
ReadBuffer(RevcBuff,RevcSize); //读数据
end;
...
Do Something
...
Athread.Connection.Disconnect
..
在运行过程中,读取数据一切正常,只是在 Athread.Connection.ReadBuff后,AThread.Connection 变成 nil. 查了 readbuff的源码,再查ReadFromStack的源码,发现ReadFromStack在
...
if not ClosedGracefully then begin
if GStack.CheckForSocketError(LByteCount, [Id_WSAESHUTDOWN, Id_WSAECONNABORTED]) then begin
LByteCount := 0;
if IOHandler <> nil then begin
DisconnectSocket;
end;
// Do not raise unless all data has been read by the user
if InputBuffer.Size = 0 then begin
....
FInputBuffer.Seek(0, soFromEnd);
FInputBuffer.WriteBuffer(FRecvBuffer.Memory^, FRecvBuffer.Size);
end;
会 DisConnectionSocket!!!!,而造成readBuff后 Athread.Connection 不能调用!而CurrentReadBuff都是调了ReadFromStack. 百思不得其解。请各位大侠帮帮忙。如何完成要求功能?
在服务端:
idTCPsExecute(AThread: TIdPeerThread);中,我做如下处理
with AThread.Connection do
begin
RevcSize := ReadFromStack(False); //取接收的长度
SetLength (RevcBuff,RevcSize); //分配空间大小
ReadBuffer(RevcBuff,RevcSize); //读数据
end;
...
Do Something
...
Athread.Connection.Disconnect
..
在运行过程中,读取数据一切正常,只是在 Athread.Connection.ReadBuff后,AThread.Connection 变成 nil. 查了 readbuff的源码,再查ReadFromStack的源码,发现ReadFromStack在
...
if not ClosedGracefully then begin
if GStack.CheckForSocketError(LByteCount, [Id_WSAESHUTDOWN, Id_WSAECONNABORTED]) then begin
LByteCount := 0;
if IOHandler <> nil then begin
DisconnectSocket;
end;
// Do not raise unless all data has been read by the user
if InputBuffer.Size = 0 then begin
....
FInputBuffer.Seek(0, soFromEnd);
FInputBuffer.WriteBuffer(FRecvBuffer.Memory^, FRecvBuffer.Size);
end;
会 DisConnectionSocket!!!!,而造成readBuff后 Athread.Connection 不能调用!而CurrentReadBuff都是调了ReadFromStack. 百思不得其解。请各位大侠帮帮忙。如何完成要求功能?