udp设置超时问题

yangtongying888 2012-07-02 02:03:42
大家好
我想在规定3秒内udp控件发数据 超过3秒则提示超时
请问怎么做

timer
ir := MilliSecondsBetween(now, dtBegin) mod 1000;
if (ir >= 0) and (ir <= iInterval) then
begin
。。。。
end
这样做不对
请问该怎么做?
...全文
738 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
mhhaifeng 2012-07-04
  • 打赏
  • 举报
回复
if biSLogin then
begin
终止timer
exit;
end;
mhhaifeng 2012-07-04
  • 打赏
  • 举报
回复
iSecond:=SecondsBetween(begTime,Now); 不行吗 为什么要mod 1000?

if iSecond>=3 then
begin
超时处理
end else
begin
没有超时处理
end;
就是这个逻辑 具体的,只能你自己处理

一般超时处理 可设一个全局变量 icount
比如登录程序 再设一个全局变量 biSLogin
当登录成功是 biSLogin :=True;
把timer 设为1秒
在timer 事件中
if biSLogin then exit;
inc(icount );
if icount>2 then
begin
超时处理
终止timer
end else
begin
重发登录信息
end;



yangtongying888 2012-07-03
  • 打赏
  • 举报
回复
问题还没有解决 大神们 救命啊
yangtongying888 2012-07-02
  • 打赏
  • 举报
回复
感谢楼上 还是不行 我那个mod 1000 和SecondsBetween 返回值是一样的
可能我写的不对, 情况是这样的:
上位机发udp 数据包到底层设备 因为有些设备需要识别一定的数据格式,所以设备没有返回信息,那么UDPUDPRead 事件是接收不到任何信息 所以没法判断 所以我现在需要在3秒内发送, 超过3秒 则提示超时
贴代码:

timer 事件:
ir := MilliSecondsBetween(now, dtBegin) mod 1000;

if MilliSecondsBetween(now, dtBegin) >= Trunc(10000 * iTimeOver) then
begin
if not OrderEdThePIC then
begin
Timer2.Enabled := False;
OrderEdThePIC := True;
end;
end
else
if (ir >= 0) and (ir <= 3000) then
begin
if (Device_Type <>'00') then
begin

c :=MakeComm(Char(StrToHex(Device_Type)));


UDP.Send('255.255.255.255',HIS_PORT,c);

end else
begin
//如果指定为
c:=MakeComm(Char(StrToHex('11')));
UDP.Send('255.255.255.255',HIS_PORT,c);

c:=MakeComm(Char(StrToHex('12')));
UDP.Send('255.255.255.255',HIS_PORT,c);

end;
mhhaifeng 2012-07-02
  • 打赏
  • 举报
回复
iSecond:=SecondsBetween(begTime,Now); 不行吗 为什么要mod 1000?

if iSecond>=3 then
begin
超时
end
yangtongying888 2012-07-02
  • 打赏
  • 举报
回复
老大们呢
yangtongying888 2012-07-02
  • 打赏
  • 举报
回复
自己顶
yangtongying888 2012-07-02
  • 打赏
  • 举报
回复
我用的是idudpserver 控件 请大侠们 多多帮忙 呵呵

1,593

社区成员

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

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