我用服务段idtcpserver,客户端用idtcpclient
服务段采集数据然后往客户端分发,经常会造成内存不能为读,然后就退出了,我是这样写的
用clients(tthreadlist)记录客户端连接信息
with Clients.LockList do
try
for i := 0 to Count-1 do // iterate through client-list
begin
RecClient := Items[i];
RecThread := RecClient.Thread;
try
if not recthread.Terminated and recthread.Connection.Connected then
begin
newcommblock.MyUserName :=recthread.Connection.Socket.Binding.PeerIP ;
NewCommBlock.Command:='RECIVE';
NewCommBlock.Msg:=GISValue;//GSMNO;J;W;State;Date
if newcommblock.MyUserName <> '' then
RecThread.Connection.WriteBuffer(NewCommBlock, SizeOf(NewCommBlock), True); // send the stuff end;
except
end;
end;
finally
Clients.UnlockList;
end;
请高手看看,什么地方出毛病了,请教别人,有的人说不能用循环调用socket,必须开辟进程,用线程很可能造成内存占用太多,满的情况,造成内存不能为读。请教高手delphi应该怎么解决,请教代码
服务段采集数据然后往客户端分发,经常会造成内存不能为读,然后就退出了,我是这样写的
用clients(tthreadlist)记录客户端连接信息
with Clients.LockList do
try
for i := 0 to Count-1 do // iterate through client-list
begin
RecClient := Items[i];
RecThread := RecClient.Thread;
try
if not recthread.Terminated and recthread.Connection.Connected then
begin
newcommblock.MyUserName :=recthread.Connection.Socket.Binding.PeerIP ;
NewCommBlock.Command:='RECIVE';
NewCommBlock.Msg:=GISValue;//GSMNO;J;W;State;Date
if newcommblock.MyUserName <> '' then
RecThread.Connection.WriteBuffer(NewCommBlock, SizeOf(NewCommBlock), True); // send the stuff end;
except
end;
end;
finally
Clients.UnlockList;
end;
请高手看看,什么地方出毛病了,请教别人,有的人说不能用循环调用socket,必须开辟进程,用线程很可能造成内存占用太多,满的情况,造成内存不能为读。请教高手delphi应该怎么解决,请教代码
这是我写的用户登录后把给每个在线用户发个信息,用以改变那些用户好友的状态图标
if qryDetail.RecordCount > 0 then
begin
qryDetail.First;
while not qryDetail.Eof do
begin
iindex := lbxUser.Items.IndexOf(qryDetail.FieldValues['fUserName']);
TIdPeerThread(MyList.LockList.Items[iindex]).Connection.WriteBuffer(sMyMsg,sizeof(sMyMsg),True);
MyList.UnlockList; qryDetail.Next;
end;
这是可以的,没有问题的。你的问题没见过,烦用with, 程序可读性太烂了,不要滥用
问题可能在
RecClient := Items[i];
RecThread := RecClient.Thread;