Welcome to my blog’s first tutorial series!
How you doing today?
I hope you’re well because this video is about to bang you on the head!
Not in a bad way of course, we’re about to learn a lot of cool stuff; but, I must warn you, grab your drink in advance and strap in that chair. 🙂
In this episode, as promised, we’re going to merge both the server and client script into one and add a bunch of functionality as well.
Analysis Before Coding
Since there’s a lot of ground to cover, let’s take a deep breath first and think about some components before diving into the code.
In the last part, we concluded the server thread and I mentioned we would work on the client thread this time. Which we will. However, before that we must port over some functions from the client script into the server script.
For example, the connect back functionality from the client script will be ported over and improved upon to allow the user to either start a new connection or be used programmatically in the main server.
Only then we’ll be able to consider firing up those client threads…
Now about the main server: we’ll have to place it inside its own function. The main reason is so we can run it in the background as a thread. This will allow us to shut it down once we finish establishing a connection and quickly fire it up again to listen for the next client.
Finally we’ll implement the text-based user interface since all of our main components are now running in the background as daemons: the server threads, the client threads and the main server.
I think that’s enough context for now so let’s jump into some code!