Author Topic: [Ararat Synapse] TCP server threading  (Read 408 times)


  • New Member
  • *
  • Posts: 29
[Ararat Synapse] TCP server threading
« on: November 02, 2019, 07:47:10 pm »

I was searching for examples of a multi-threaded server using Ararat Synapse and found this thread:,21024.msg122614.html#msg122614

It wasn't really useful in the end because the code given had too many problems.

I've now written my own multi-threaded TCP server solution.  It uses hashed buckets for workers so the thread count can stay fairly low.  This is quite unique, I haven't seen any other solutions using this method. 

I'm putting the code in the public domain but I would like to have some attribution if you use it.  Also, if you do use it and improve it somehow, I'd like to hear from you, of course.  I've made the license the same as Ararat Synapse.

The code is part of my M3wP Yahtzee game and requires a unit from there but only to define the message class.  I should really break that out into another unit since it doesn't really require the full detail of the Yahtzee message class.  I've put the definition of the class in comments for you.

It would be easy enough to change the hash function and number of buckets but I think 32 workers is a good limit for most applications, anyhow.

Here is the link:

I hope you like it!



  • New Member
  • *
  • Posts: 29
Re: [Ararat Synapse] TCP server threading
« Reply #1 on: November 02, 2019, 08:05:40 pm »
Oh I forgot..  To use it, simply call the code like this:

Code: Pascal  [Select][+][-]
  2.         TCPServer.TCPServer:= TTCPServer.Create;
  3.         TCPServer.TCPServer.OnConnect:= DoConnect;
  4.         TCPServer.TCPServer.OnDisconnect:= DoDisconnect;
  5.         TCPServer.TCPServer.OnReject:= DoReject;
  6.         TCPServer.TCPServer.OnReadData:= DoReadData;
  8.         TCPListener:= TTCPListener.Create(aPort);

When you're done, call:

Code: Pascal  [Select][+][-]
  1.         TCPListener.Terminate;
  2.         TCPListener.WaitFor;  
  4. //Optional
  5.         TCPServer.Free;
  6.         TCPServer:= nil;




TinyPortal © 2005-2018