TServerSocket的多线程 长连接下面的程序能实现吗?
我现在做的程序,会不停收到客户段重新连接上来的信息,
然后又重复发送数据给客户端,内存消耗会不断的加大,怎么解决这个问题
我的客户端数量最多80个,一般30个。
下面我贴出代码
inherited FreeOnTerminate := True;
CoInitialize(nil);
Query1 := TAdoquery.Create(nil);
Query2 := TAdoquery.Create(nil);
Query1.Connection := Form1.ADOConnection1;
Query2.Connection := Form1.ADOConnection1;
while not Terminated and ClientSocket.Connected do
try
SocketStream := TWinSocketStream.Create(ClientSocket, 60000);
try
FillChar(struPrisoner, SizeOf(TPrisoner), 0);
if SocketStream.Read(struPrisoner, SizeOf(TPrisoner)) = 0 then
begin
// If we didn't get any data after 60 seconds then close the connection
ClientSocket.Close;
Terminate;
end;
if ClientSocket.Connected then begin //正常的处理
sleep(1);
b := false;
//**************************** protocol ******************************************//
StrCopy(@ArrRoom, @struPrisoner.szRoom);
szPrison := ArrRoom;
if struPrisoner.iCommand = 7 then
begin
//查询数据库内容发送给客户端
Query1.Next;
end;
icommand := 17;
ClientSocket.SendBuf(icommand, SizeOf(integer)); end; if struPrisoner.iCommand = 14 then
begin
//查询数据库内容发送给客户端
ClientSocket.SendBuf(struPrisonInfo, sizeof(TPrisonInfo));
end;
{此处处理协议部分}
//**************************** protocol ******************************************//
if b = true then begin //接受close命令后 b=true
sleep(1);
ClientSocket.Close;
Terminate;
end;
end;
finally
SocketStream.Free;
end;
except
//HandleException;
ClientSocket.Close;
Query1.Free;
Query2.Free;
Terminate;
end;
CoUninitialize;
我现在做的程序,会不停收到客户段重新连接上来的信息,
然后又重复发送数据给客户端,内存消耗会不断的加大,怎么解决这个问题
我的客户端数量最多80个,一般30个。
下面我贴出代码
inherited FreeOnTerminate := True;
CoInitialize(nil);
Query1 := TAdoquery.Create(nil);
Query2 := TAdoquery.Create(nil);
Query1.Connection := Form1.ADOConnection1;
Query2.Connection := Form1.ADOConnection1;
while not Terminated and ClientSocket.Connected do
try
SocketStream := TWinSocketStream.Create(ClientSocket, 60000);
try
FillChar(struPrisoner, SizeOf(TPrisoner), 0);
if SocketStream.Read(struPrisoner, SizeOf(TPrisoner)) = 0 then
begin
// If we didn't get any data after 60 seconds then close the connection
ClientSocket.Close;
Terminate;
end;
if ClientSocket.Connected then begin //正常的处理
sleep(1);
b := false;
//**************************** protocol ******************************************//
StrCopy(@ArrRoom, @struPrisoner.szRoom);
szPrison := ArrRoom;
if struPrisoner.iCommand = 7 then
begin
//查询数据库内容发送给客户端
Query1.Next;
end;
icommand := 17;
ClientSocket.SendBuf(icommand, SizeOf(integer)); end; if struPrisoner.iCommand = 14 then
begin
//查询数据库内容发送给客户端
ClientSocket.SendBuf(struPrisonInfo, sizeof(TPrisonInfo));
end;
{此处处理协议部分}
//**************************** protocol ******************************************//
if b = true then begin //接受close命令后 b=true
sleep(1);
ClientSocket.Close;
Terminate;
end;
end;
finally
SocketStream.Free;
end;
except
//HandleException;
ClientSocket.Close;
Query1.Free;
Query2.Free;
Terminate;
end;
CoUninitialize;
解决方案 »
- 多表删除问题
- scrollbox鼠标滚轮事件无效
- 300分,请教高手,如果用DELPHI将数据导入到EXCEL里面后做柱状图?
- OA问题:如何将图章(bmp,jpg)插入到word中去!
- 文本框的简单问题?
- 提个老问题:不用控件用ADO分别给出连接MDB和SQL7.0或者SQL2000的方法,多谢多谢各位大侠!
- 急切求助!如何控制 richedit 编辑区与所灌入文本左侧的边距
- 求加密算法。
- 为什么对象树中对象前有个问号 怎样解决
- 像找一个可以制作成XP风格的菜单控件
- pagecontrol的动态嵌套创建
- query 返回 多个结果,怎么汇总 到一个里变量,直接或间接的方法都可以,比方说query结果有只有3行呢?就一列的情况下
//
//动态创建释放建议参考如下代码
aQuery := TADOQuery.Create(nil)
try
//
finally
aQuery.Free;
end;