DataSnap Server

DSServer1Disconnect

这个函数什么时候执行?

void __fastcall TServerContainer1::DSServer1Disconnect(TDSConnectEventObject *DSConnectEventObject)

客户端正常退出的时候,会执行,SQLConnection1->Close();

如果客户端异常退出,进程异常终止,单独的demo异常终止会执行DSServer1Disconnect,但是主框架程序异常终止为何不触发??

 

Project E:\AppServer\myserver.exe faulted with message: 'application-defined exception (code 0x0eedfade) at 0x75e4c41f'. Process Stopped. Use Step or Run to continue.

 

是你的子线程直接操作 VCL的缘故??

 

方式一

这样创建的Form,进程中断也正常,触发了 DSServer1Disconnect。

Application->CreateForm(__classid(Tfrmyhdl), &frmyhdl);

方式二

如果用下面的方式创建Form,进程中断就不触发DSServer1Disconnect,server就不正常了!
frmyhdl = new Tfrmyhdl(Application);
frmyhdl->ShowModal();
delete frmyhdl;

 

但是不能因此而改变客户端的写法吧,如果客户端突然停电,服务器难道也要异常退出?所以应该还是服务端DataSnap的问题吧

客户端不调用方法,只连接,不关闭连接,也是出现这种情况,再次验证了方式二的窗体确实有问题。

dm->SQLConnection1->Close();
dm->SQLConnection1->Params->Values["HostName"] = LabeledEdit1->Text;
dm->SQLConnection1->Params->Values["Port"] = LabeledEdit2->Text;
dm->SQLConnection1->Open();

 

从服务端着手研究,新建一个空白datasnap服务端,然后客户端连接不关闭连接,进程中断,服务端是好的,没有退出。

下来比较空白工程和自己写的server代码里有什么是线程不安全的?

果然,ServerContainerUnit1.cpp里的所有事件的记录日志的功能去掉就OK啦,不闪退了。

客户端异常中断后不触发DSServer1Disconnect事件,DSTCPServerTransport1Disconnect事件里也获取不到参数信息。所以最终解决方案是删除DSTCPServerTransport1Disconnect事件就可以了。

 

经过试验,取消ServerContainerUnit1事件就正常了,屏蔽里边的代码事件保留也不行,必须把事件代码删除完,事件为空

void __fastcall TServerContainer1::DSTCPServerTransport1Disconnect(TDSTCPDisconnectEventObject Event) 客户端两种方式都可以正常了,服务端也不退出了。

ServerContainerUnit1其他事件代码保留正常,就DSTCPServerTransport1Disconnect有问题啊!

delphi里DSTCPServerTransport1Disconnect事件正常触发,可以获取信息(TIdTCPConnection*)Event.Connection,但是在c++builder里,这个事件触发了,但是Event.Connection无法获取真实的值。

有人也发现c++builder的这个datasnap的不过。

http://codeverge.com/embarcadero.datasnap/tdstcpdisconnecteventobject-is-real-bug/1097541

In C++Builder XE2 and XE3 event handler
for TCP_connect:

void __fastcall TServerContainer1::DSTCPServerTransport1Connect(TDSTCPConnectEventObject &Event)
{
   Form1->ListBox1->Items->AddObject(IntToHex((int)Event.Connection,8),NULL) ;
}

and for TCP_disconnect

void __fastcall ServerContainer1::DSTCPServerTransport1Disconnect(TDSTCPDisconnectEventObject Event)
{
   Form1->ListBox1->Items->AddObject(IntToHex((int)Event.Connection,8),NULL) ;
}
passed not equal objects Event.Connection

in parameters the object Event.Connection is not equalent in both handlers, but for DELPHI XE2 and XE3 this handlers passes equalent objects Event.Connection and all is well
 In CPU-view the real address of Event.Connection is saved in register EDX
and this handler of disconnect is very well:
void __fastcall TServerContainer1::DSTCPServerTransport1Disconnect(TDSTCPDisconnectEventObject Event)
{
  TObject* PCONNECT=(TObject*)_EDX;
   Form1->ListBox1->Items->AddObject(IntToHex((int)PCONNECT,8),NULL) ;
}

on_connect  and on_disconnect passes the same objects Connection,  and visually can make sessions and users lists that is "ONLINE"

Edited by: matsenko vladimir on Jan 31, 2013 10:50 AM
View Code

相关文章:

  • 2022-12-23
  • 2021-08-03
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2021-08-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案