Taking our servers forward

There are a number of things that we can do to improve our servers. For multithreaded systems, it's common to have a mechanism for capping the number of threads in use at any one time. This can be done by keeping a count of the active threads and immediately closing any new incoming connections from clients while it's above a threshold.

For all our servers, we would also want to add a logging mechanism. I strongly recommend the standard library logging module for this, the documentation for this is complete and full of good examples. The basic tutorial is a good place to start if you've not used it before, and it can be found at https://docs.python.org/3/howto/logging.html#logging-basic-tutorial.

We also want to handle errors more comprehensively. Since the intention is that our server should be long running with minimal intervention, we want to make sure that nothing less than a critical exception causes the process to exit. We also want to make sure that errors that occur when handling one client do not affect other connected clients.

Finally there are some basic features of chat programs that it may be fun to add: letting users enter a name, which would be shown beside their messages on the other clients; adding chat rooms; and adding TLS encryption to the socket connections to provide privacy and security.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.145.158