I’ve been thinking, which is itself a scary thought.
My constant on/off project has been a full 2D game engine running in Python with both a client built in PySDL2 using its OpenGL renderer, and a server that was built in Flask/Socketio. The reason I chose Flask is because 1) It makes the networking easy with flask-socketio and 2) I wanted a REST API that I could expose to admins/developers for live interaction and management of the world and its players. However, I have reached a point where Flask is beginning to let me down (and is probably my shitty codes fault). Due to this, and rampant curiosity, I decided to port to FastAPI just to give it a spin.
After porting my codebase over to FastAPI from Flask over the weekend (which did not take long at all, I highly recommend FastAPI) I was stuck with a problem- FastAPI has built in websockets, and also has support for socketio which I was using before, but I wanted something lower level. This leads me to ZeroMQ, usually called just ZMQ. One of the founders has a fantastic write-up here, so I’ll leave that to him. Basically ZMQ is a high-performance asynchronous messaging library- it allows code to talk to other code, and has a translation in almost every major programming language (and to the delight of a certain coworker, even Perl).
What this really means is that not only can your code talk to other code on different systems, it can talk to code in different languages as long as a contract has been formed for the messaging standard and information passed. And since we are working with a messaging library, it has its own wire-level protocol called ZMTP that works over a TCP connection- though you can escape this and access raw TCP or another protocol using a ZMQ_STREAM, which I have not experimented with yet. This also means its designed for scale and speed, as per the documentation: ‘You could throw thousands of clients at this server, all at once, and it would continue to work happily and quickly.‘
However, this isn’t the real reason I am doing a rare blog post today. The real reason is one of the founders, Pieter Hintjens, who unfortunately passed in 2016. As linked in the ZMQ guide, and available on his blog in PDF, Pieter has written many science fiction stories that discuss what it means to live in a connected world and the digital age. In the introduction, he refers to this super species of future-humanoids as ‘the Culture’. I have not read far enough in to give a clear rundown just yet, but I can already say I highly recommend it. Even the tagline pulls you in:
The whole planet is getting connected, and building vast new communities. The on-line world thinks faster, and thinks different. Smart, fast, and creative, these new communities are a real challenge to old power and old money. And old money, after its War on Drugs, and War on Terror, is now launching its War on the Internet.
His writings on the future, its technologies, and what it all may mean when viewed through our current context is sublime, and I absolutely adore his breakdown of the physics of software in the ZMQ guide- that the physics of software is not programs and code; but the physics of people themselves, our limitations, and our desire to work together to solve problems. I really can’t recommend it enough. I’ll be linking his blog below for any who are interested.
Leave a Reply