简体   繁体   中英

Udp Server on ActiveX Form

When I use TIdUDPServer on ActiveXForm , OnUDPRead event of the Udp Server does not trigger.
If I check IdUDPServer.Active status, it's "true". But why OnUDPRead never triggered?

TIdUDPServer is a multi-threaded component. Each item in its Bindings collection listens for data in its own worker thread.

The TIdUDPServer.ThreadedEvent property is false by default, which means each Binding triggers the OnUDPRead event in the context of the main UI thread by calling TThread.Synchronize() , which does not work inside of a DLL unless both DLL and EXE are compiled with Runtime Packages enabled so they share a common copy of the RTL. Otherwise, the DLL will have its own separate copy of the RTL than the main EXE's RTL (assuming the EXE is using the VCL at all). Without Runtime Packages enabled, the main EXE would have to explicitly call into the DLL periodically to pump the DLL's message queue for Synchronize() requests, since they will not appear in the EXE's message queue (assuming the EXE would even know how to process them if they did).

If you set ThreadedEvent to true, Synchronize() will not be used, thus the OnUDPRead event will be triggered in the context of each Binding thread. You would just have to make sure that your OnUDPRead handler code is written to be thread-safe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM