Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I run TIdTCPServer inside a Context/Thread?
#1
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!
Reply
#2
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.

Reply
#3
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
Reply
#4
(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.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)