用服务器端线程接收客户信息 ( 积分: 100 )

  • 主题发起人 主题发起人 polmza13
  • 开始时间 开始时间
P

polmza13

Unregistered / Unconfirmed
GUEST, unregistred user!
用服务器端线程接收客户信息
在 while (not Terminated) and self.ClientSocket.Connecteddo
断点调试
可以正确获得客户信息
可是程序走完之后就出错
unit Unitseverhread;
interface
uses
Classes,ScktComp,unitdata,SysUtils;
type
Tseverhread = class(TServerClientThread)
private
aStream : TWinSocketStream;
{ Private declarations }
protected
procedure ClientExecute;
override;
public
constructor Create(ACreateSuspend:boolean;ASocket:TServerClientWinSocket);
end;
implementation
uses
unitsever;
constructor Tseverhread.Create(ACreateSuspend: boolean;
ASocket: TServerClientWinSocket);
begin
inherited Create(ACreateSuspend,ASocket);
end;
procedure Tseverhread.ClientExecute;
var
Packet:PPacket;//数据传送包
RegPacket:PRegPacket;//定义上线包
begin
aStream := TWinSocketStream.Create(self.ClientSocket, 1000);
while (not Terminated) and self.ClientSocket.Connecteddo
begin
if astream.WaitForData(1000) then
begin
new(packet);
new(RegPacket);
fillchar(Packet.Data,1024,#0);
Astream.ReadBuffer(Packet^,sizeof(TPacket));
if Packet^.FType='0' then
begin
fillchar(RegPacket^.name,21,#0);
move(Packet^.Data,RegPacket^,sizeof(TRegPacket));
frmsever.MemoSever.Lines.Add(RegPacket.name+'上线了');
dispose(RegPacket);
dispose(Packet);
end;
end;
sleep(100);
end;
end;

end.
 
线程中使用 Sleep, 无语了.....
 
问题已经自己解决了
from单元的错误
线程创建后应该 给var SocketThread
而不是 自己定义的Severhread
 
后退
顶部