zoukankan      html  css  js  c++  java
  • DataSnap的如果网络断线,如何恢复?

    语言:Xe2 框架:DataSnap
    问题:DataSnap很简单,把一个二层的程序改写成三层,很简单就实现了,例如:把原先的二层访问函数,堆到TServerMethods1单元即可,然后就实现了三层。但是在测试时有个问题,生产环境可能非常恶劣,经常回发生断线情况,我们要保证可以自动恢复功能,即断线一段时间,可以修复,二层很简单,直接做一个timer,如果访问失败,就定时去连接,可以成功恢复。但是在datasnap时,自动恢复功能无法实现,主要表现为,比如正常访问中间层一次后,关闭中间层,此时客户端访问失败,跟踪后用客户端timer重新连接访问中间层,每次
    出现以下各种不同错误(有10054,10038,10061错误),并不能实现恢复。


     raised exception class EIdNotASocket with message 'Socket Error # 10038
    Socket operation on non-socket.'.

    ----------
    Debugger Exception Notification
    ----------
    Project PrjV.exe raised exception class EIdCouldNotBindSocket with message 'Could not bind socket. Address and port are already in use.'.
    ----------
    Break   Continue   Help   
    ----------




    ----------
    Debugger Exception Notification
    ----------
    Project PrjV.exe raised exception class EIdClosedSocket with message 'Disconnected.'.
    ----------
    Break   Continue   Help   
    ----------


    ----------
    Debugger Exception Notification
    ----------
    Project PrjV.exe raised exception class EIdSocketError with message 'Socket Error # 10022
    Invalid argument.'.
    ----------
    Break   Continue   Help   
    ----------

    尤其是有2个错误,Session has expired,最后会出现一个index of bound越界错误,
    一旦出现就无法自动恢复(调用timer重复调用一个最简单的中间函数GetDbServerTime)

    ps:我也改了lifecycle,session 改成Invocation,Application,好像也不行。

    大家都知道datasnap底层是indy实现的,怎么可以实现断线datasnap自动恢复功能?

    timer代码很简单:
    var adbsevertime :TDateTime;
    begin
      try
          adbsevertime :=
              ClientModule1.ServerMethods1Client.GetDbServerTime;
          if adbsevertime <> 0 then
          begin
            gdbStatus := true;
            TimerReconnet.Enable:=false;
          end;
         
        except
          on E: Exception do
          begin
           
              TimerReconnet.Enable:=true;
          end;
        end;
    end;

    GetDbServerTime是dephi自动生成的客户端访问中间层的方法

    网上找到三种方法:
    http://www.cnblogs.com/yagzh2000/archive/2013/04/27/3046637.html

    http://blog.csdn.net/sunstone/article/details/5023718
    http://blog.163.com/bin0315@126/blog/static/4066264220128414025829/
    类似)


    http://bbs.2ccc.com/topic.asp?topicid=396438

    我每个测试一下,到时候结果通知大家。

  • 相关阅读:
    《程序员修炼之道:从小工到专家》阅读笔记02
    第二阶段团队冲刺10
    第二阶段团队冲刺09
    周总结
    第二阶段团队冲刺08
    第二阶段团队冲刺07
    小A和小B和幽灵追两人(双向BFS)
    C. 真假亚瑟王(暴力)
    小A的柱状图(栈的应用,找左右边界)
    小A买彩票
  • 原文地址:https://www.cnblogs.com/findumars/p/6279395.html
Copyright © 2011-2022 走看看