There are a number of design guidelines that can help developers build fast and reliable applications while avoiding some common pitfalls of writing time dependent asynchronous code.
When building an application that handles multiple connections (client or server), create an instance of a class for each connection with a collection object to hold each instance of this class. When the connection is created (ConnectionRequest event for servers and ConnectionEstablished event for clients) is when the new instance should be created and added to the collection, and keyed by the socket handle (a socket handle parameter is included in almost every event, which makes it easy to retrieve the object that is related to a particular connection). When the connection terminates is when the related object should be removed from the collection (in the ConnectionTerminated event).
Keep blocking operations to a minimum within events. When code execution is in an event, background threads are still sending and receiving data, however, the code that is executing in an event maintains a lock on socket related data so that the application can access it, and so that a socket (and it’s object) is not destroyed while in an event. If a database is being accessed, ensure that access to it is asynchronous. Consider simply accumulating data in the events and then using a separate mechanism to process data outside the events, so as not to block sending and receiving. If the component receives data while execution is in code other than a SocketQ event, it will try to signal the application. If the application is in a blocking state, it will queue the notification to be received as soon as the application is ready, and all send and receive operations continue unhindered.
If you are building a high performance server application, keep UI updates to a minimum. Consider updating the UI every 5 or 10 seconds if you must, instead of providing real time data display, and your applications performance can increase by an order of magnitude.
Ensure that you have a good logging mechanism in place while developing an application. A good logging mechanism is the key to finding obscure bugs, or occasional behavior in an asynchronous environment where timing must be taken into account.