DELPHI的Indy IdTCPClient控件如何主动接收数据

wx810 2012-11-23 05:05:40
如题
idtcpserver能发送数据,但不知道idtcpclient如果主动去取。目前是用idtcpclient再发一条信息发完后马上去读,可以读到由idtcpserver写进的数据。
...全文
1893 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wx810 2012-11-23
  • 打赏
  • 举报
回复
谢谢楼上的给我启发,好象可以了,分就给你吧。我使用readln,然后判断是否为空
SQLDebug_Fan 2012-11-23
  • 打赏
  • 举报
回复
如果没有返回需要加超时,或者服务器返回错误码。
wx810 2012-11-23
  • 打赏
  • 举报
回复
这是我线程类中的代码: unit ClientHandleThread; interface uses Classes,SysUtils; type TClientHandleThread = class(TThread) private { Private declarations } servercmd:integer; serverMsg:string; procedure HandleInput; protected procedure Execute; override; end; implementation uses Unit1; { Important: Methods and properties of objects in visual components can only be used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure TClientHandleThread.UpdateCaption; begin Form1.Caption := 'Updated in a thread'; end; } { TClientHandleThread } procedure TClientHandleThread.Execute; begin while not Terminated do begin if not Form1.IdTCPClient1.Connected then Terminate else try servercmd:=Form1.IdTCPClient1.IOHandler.ReadInteger; Synchronize(HandleInput); except end; end; end; procedure TClientHandleThread.HandleInput; begin case servercmd of 0: else end; end; end. case部分怎么判断有没有返回
SQLDebug_Fan 2012-11-23
  • 打赏
  • 举报
回复
TIdTcpClient是阻塞式调用,用一个线程调用Read方法,有返回就读到数据了。

5,930

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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