Atozed Forums
Can I run TIdTCPServer inside a Context/Thread? - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Indy (https://www.atozed.com/forums/forum-8.html)
+--- Forum: Indy General Discussion (https://www.atozed.com/forums/forum-9.html)
+--- Thread: Can I run TIdTCPServer inside a Context/Thread? (/thread-4610.html)



Can I run TIdTCPServer inside a Context/Thread? - Justin Case - 10-23-2024

Hi

Might sound like a daft question and you're probably thinking I'd be crazy to want to but I am working on a server that will be able to accept plugins to add extra functionality. As part of that, I would like to be able to run plugins as part of the main server program but also per user by creating a plugin loader inside the thread using the threads Data object to keep track of it.

I am using Max's TMxPluginLoader component / plugins.

What I would like to be able to do is for example, send a plugin to the server which has an FTP server for example or perhaps a SMTP server. I know that I could do that in the main program thread but I'd like to be able to also do this in a thread so that other users don't get access to the same plugin and mess things up.

Delphi logic and parent / descendant classes says this should be possible but as Indy is quite complex in nature server-wise, I thought I best check with the experts!


RE: Can I run TIdTCPServer inside a Context/Thread? - rlebeau - 10-23-2024

Yes, you can create and run Indy servers inside of worker threads. Just make sure your server event handlers are written in a thread-safe manner.


RE: Can I run TIdTCPServer inside a Context/Thread? - Justin Case - 10-23-2024

By thread safe, do you mean as a normal server would? - code in the event handlers from the Object Inspector or is there another technique I need to use? - I'm assuming that inside the worker thread, a created server would then create its own threads inside that thread?

Thanks


RE: Can I run TIdTCPServer inside a Context/Thread? - rlebeau - 10-23-2024

(10-23-2024, 07:42 PM)Justin Case Wrote: By thread safe, do you mean as a normal server would? - code in the event handlers from the Object Inspector or is there another technique I need to use?

What I mean is, any data being shared inside the events across thread boundaries must be properly synchronized, etc.

(10-23-2024, 07:42 PM)Justin Case Wrote: I'm assuming that inside the worker thread, a created server would then create its own threads inside that thread?

Yes. Indy servers create a thread for each Binding they are listening on, and in the case of TIdTCPServer, also a thread for each client that is accepted.