TIdTCPServer的OnExecute事件不写代码,我只需要他的onConnect事件,为什么会报错呢?

yczyk 2005-07-16 10:45:04
请问,TIdTCPServer的OnExecute事件不写代码,我只需要他的onConnect事件,为什么会报错呢?
而且,如果我写个空事件在OnExecute中,为什么会出现资源占用100%呢?
...全文
369 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wizardqi 2005-11-14
  • 打赏
  • 举报
回复
我建议楼主的信息读去放在OnExecute中,哪怕只有一次信息读取。
wizardqi 2005-11-14
  • 打赏
  • 举报
回复
这个简单,如果IdTCPServer组件不为OnExecute指定处理过程,就会得到EIdNoExecuteSpecified
异常,你可以查看以下两个代码片段:
function TIdTCPServer.DoExecute(AThread: TIdPeerThread): boolean;
var
i: integer;
LLine: string;
begin
if CommandHandlersEnabled and (CommandHandlers.Count > 0) then begin
Result := True;
if AThread.Connection.Connected then begin //APR: was While, but user can disable handlers
LLine := AThread.Connection.ReadLn;
// OLX sends blank lines during reset groups and expects no response. Not sure
// what the RFCs say about blank lines.
// I telnetted to some newsservers, and they dont respond to blank lines.
// This unit is core and not NNTP, but we should be consistent.
if Length(LLine) > 0 then begin
DoBeforeCommandHandler(AThread, LLine); try
for i := 0 to CommandHandlers.Count - 1 do begin
with CommandHandlers.Items[i] do begin
if Enabled then begin
if Check(LLine, AThread) then begin
Break;
end;
end;
end;
if i = CommandHandlers.Count - 1 then begin
DoOnNoCommandHandler(LLine, AThread);
end;
end;//for
finally DoAfterCommandHandler(AThread); end;
end;//if >''
end;
end else begin
Result := Assigned(OnExecute);//注意这里,当你没有为OnExecute指定处理是该函数就会返回False;
if Result then begin
OnExecute(AThread);
end;
end;
end;

procedure TIdPeerThread.Run;
begin
try
try
if not Connection.Server.DoExecute(Self) then begin//如果DoExecute返回False抛出异常
raise EIdNoExecuteSpecified.Create(RSNoExecuteSpecified);
end;
。。。。。。。
end;
将计就计123 2005-11-14
  • 打赏
  • 举报
回复
要只是想通知的话,不用维护一个连接
用UDP不是更方便吗
日总是我哥 2005-07-17
  • 打赏
  • 举报
回复
procedure TIdThread.Execute;
begin
try
try
BeforeExecute;
while not Terminated do begin
if Stopped then begin
DoStopped;
// It is possible that either in the DoStopped or from another thread,
// the thread is restarted, in which case we dont want to restop it.
if Stopped then begin // DONE: if terminated?
if Terminated then begin
Break;
end;
Suspended := True; // Thread manager will revive us
if Terminated then begin
Break;
end;
end;
end;

try
BeforeRun;
try
////////////////////////注意这里////////////////////
//一有连接线程创建时执行的事件 
while not Stopped do begin
Run;
end;
finally
AfterRun;
end;//tryf
finally
Cleanup;
end;

end;//while NOT Terminated
finally
AfterExecute;
end;
except
on E: Exception do begin
FTerminatingExceptionClass := E.ClassType;
FTerminatingException := E.Message;
DoException(E);
Terminate;
end;
end;//trye
end;


//这是被调用的方法
procedure TIdPeerThread.Run;
begin
try
try
//如果没有写DoExecute事件,则异常
if not Connection.Server.DoExecute(Self) then begin
raise EIdNoExecuteSpecified.Create(RSNoExecuteSpecified);
end;
except
// We handle these seperate as after these we expect .Connected to be false
// and caught below. Other exceptions are caught by the outer except.
on E: EIdSocketError do begin
Connection.Server.DoException(Self, E);
case E.LastError of
Id_WSAECONNABORTED // WSAECONNABORTED - Other side disconnected
, Id_WSAECONNRESET:
Connection.Disconnect;
end;
end;
on E: EIdClosedSocket do begin
// No need to disconnect - this error means we are already disconnected or never connected
Connection.Server.DoException(Self, E);
end;
on E: EIdConnClosedGracefully do begin
// No need to Disconnect, .Connected will detect a graceful close
Connection.Server.DoException(Self, E);
end;
end;
// If connection lost, stop thread
//如果没有断开连接,则一直执行...........所以占用资源100%
if not Connection.Connected then begin
Stop;
end;
// Master catch. Catch errors not known about above, or errors in Stop, etc.
// Must be a master catch to prevent thread from doing nothing.
except
on E: Exception do begin
Connection.Server.DoException(Self, E);
raise;
end;
end;
end;
cjf1009 2005-07-16
  • 打赏
  • 举报
回复
关注先
日总是我哥 2005-07-16
  • 打赏
  • 举报
回复
星哥,小的这厢有礼了:)
yczyk 2005-07-16
  • 打赏
  • 举报
回复
下面是部分代码:
for iCount := 0 to SendList.Count - 1 do
begin
try
try
tcpSendOut.Host := SendList[iCount];
tcpSendOut.Connect(DrinkTransOutTime);
except
MemoDaily.Lines.Add(format(sSendOutErr,[SendList[iCount]]));
end;
finally
tcpSendOut.Disconnect;
end;
end;
我有一个SendList列表,这里有待发的服务器列表,他们端口都相同
因为他们执行的是同一个事件,只是在不同的机器上执行
yczyk 2005-07-16
  • 打赏
  • 举报
回复
我的客户端一Connect上Server后,就马上断掉。
我这样做其实就是实现这样一个过程:
一个程序通知另一个程序做事,TIdTCPClient向TIdTCPServer发连接信息,发完后就断开,TIdTCPServer收到信息就做某事,我直接在Connection事件里做的,无须在OnExecute做任何事。可是接收到连接后就报错,你报错就报错呗,但结果造成我在Connection里的打印失败。真是晕了!
loveyzz 2005-07-16
  • 打赏
  • 举报
回复
说说清楚,哪一端报错?
你贴的那端代码,没有write那Server端哪里收得到数据?
lovend 2005-07-16
  • 打赏
  • 举报
回复
帮你顶
hqhhh 2005-07-16
  • 打赏
  • 举报
回复
关注:
UP
源码下载地址: https://pan.quark.cn/s/7a349ad53637 在地理信息系统(GIS)领域中,土地利用现状图被视为一种核心的数据可视化手段,其主要功能在于呈现特定区域的土地使用格局,涵盖农业、住宅、工业、绿地等多样化的土地利用类型。此类信息对于城市规划、环境分析、土地监管以及决策制定具有基础性作用。在编制土地利用现状图的过程中,符号库的构建与样式匹配环节是保障地图具备清晰度、精确性及视觉美感的核心步骤。所谓"样式匹配",是一种技术手段,旨在让用户能够将特定的符号或视觉样式与地图中的数据要素建立关联。在本资源中,提及的"样式匹配lyr"文件或许是一个ArcGIS(一种广受欢迎的GIS软件)所使用的图层样式文件,该文件内含了预设的图例符号及使用规范,用以区分不同的土地利用类别。用户若将此lyr文件导入至个人项目中,便能够迅速为土地利用现状图层赋予统一且专业的视觉表现。符号库则是指存储各类图形符号的集合,这些符号在地图上代表了不同的地理要素。对于土地利用现状图而言,每一类土地通常都对应一个特定的符号,比如农田可能以绿色填充图案来表现,而建筑用地则可能采用灰色的实心形状。这些符号库对于统一地图的视觉呈现至关重要,有助于观者迅速把握地图所传递的信息。在ArcGIS软件中,用户能够通过"图层属性"界面来调控图层的视觉样式。在该界面中,用户可以选择"符号"面板来设定数据的可视化方式,或选择"标签"面板来管理要素的标注规则。借助"加载样式"功能,用户可以将"样式匹配lyr"文件中的样式规则应用到当前图层,以此规避逐一对每个土地利用类型进行符号的手动配置。不仅如此,为了达成卓越的可视化效果,可能还需对其他图层属性进行微调,例如调节透明度、设置比例尺依赖...

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧