How I Wrote a Client-Server App in Two Minutes Flat
I had a problem, and I needed a solution. If you work in IT, you’ve probably come across a similar problem before. In general, it looks something like this:
- You have data on computer A that you need to send to computer B over the network.
- Upon receipt of the data, computer B should react.
- Automate the repetition of this process.
At a fundamental level, this is the model of a client-server application. Infinite amounts of complexity can be built on top of this model, but at it’s core, these three simple bullet points illustrate the basic operation.
I needed to write a client-server application. A basic one. I didn’t need a flashy front end. No GUI was required. It should execute from the command line, simply and elegantly.
I was hoping there would be a resource that provides a framework for this basic client-server model. Something that makes exchanging data between two computers easy to build and customize.
After some searching, instead what I found were resources pointing me towards a list of library functions and code snippets that needed to be modified and pieced together to achieve some semblance of what I was looking for. A neatly packaged framework, it was not.
So I built one myself.
“Necessity is the mother of invention” — Unknown
I called my project “Spring Server” — A springboard for client-server applications. On the github page, it boasts:
The goal of this project is to provide a simple and robust framework that enables the swift creation of client-server applications.
In testing this goal, I was able to create a client-server application in 2 minutes flat. Admittedly, it’s a very basic application, but I hope it proves the concept.
The above screencap is the end result of that 2 minutes.
The client computes it’s own CPU utilization and sends that value to the server at 5 second intervals. The server then logs it.
Here is a video of the build process, for the curious.
Admission: You’ll notice that at one point in the video I pasted a block of code that computes the CPU, instead of taking the time to type it. What I wanted to demonstrate was the speed at which I was able to achieve the basic client-server model, not me fumbling though the process of gathering system resources. Cheating? Maybe. It was only 12 lines of code.
Just as the basic model of a client-server application is simple, I’ve tried to make simplicity the cornerstone of Spring Server. It makes it dead simple to achieve the three bullet points above: Exchange, React, Repeat.
And not just between 2 computers. The server component can manage up to 1028 concurrent client connections, of which it can easily facilitate the exchange of data between any or all of them.
Even though I focus on simplicity, Spring Server is capable of far more complex applications for those who have the development skills. I postulate that it can be used as the underlying framework for anything from an online poker game, to a chat application, to an enterprise monitoring solution, to a file-sharing program.
Read the full documentation on github and be sure to star it if you like it:
As always, please reach out to me on github if you have any issues.
Thanks!