Client accessing a server from different threads

(Lagarrigue, Frederic (Reigate)) #1

I have a .NET client which is accessing a Delphi server. All is working well, but I now want to access the server from multiple threads. I currently have a main channel and an event channel (both HTTP client channels), an event receiver and an binary message. Do I need one of each for each thread? Or could I share event channel and receiver? And what about message?

(antonk) #2

You can access client channel from different threads.However simple Http and Tcp client channels are not thread-safe, so you will hve to ensure that your code won’t try to send several reqests sumultaneously (you’ll get an ecxeption in that case). SuperHttp and Super tcp client cannels can be accessed from different threads and they are thread-safe.

(Lagarrigue, Frederic (Reigate)) #3

However, I would like to be able to do simultaneous communication and if one thread is using the channel then it is busy and another thread can’t use it. which is why I need a channel per thread (or a pool of channels perhaps)

(antonk) #4

This will work too. F.e. we use a pool of service proxy objects in the Olympia-based session and event managers.

Remoting SDK provides object pool base classes that make this easy to implement. F.e. go to the OlympiaServerSessionManager.cs sources. There a connections pool is defined as

this.fConnectionPool = new CustomObjectPool<IOlympiaSessionManager>(this.CreateSessionManagerHandler, PoolBehavior.Wait, 0, 10, 1000);

and connections are later used from different threads as easy as

	serviceConnection = this._connectionPool.AcquireInstance();
	....Perform server call

(Lagarrigue, Frederic (Reigate)) #5

Ok that’s great. Is it possible to use a single channel for events though? Or should I have a channel per thread for events too?