Welcome to Sockets!
Sockets is cool module that lets you run Python code across multiple computers! You can communicate between computers in encoded strings, allowing you to have meaningful multiplayer interaction.This is especially popular for multiplayer games, but is also applicable in many other projects
What do I need to know?
I'd recommend following along with Kyle's starter code (that's me!) which is modified from Rohan's starter code, since that is what I'll be referring to for this tutorial. Download and open the files in Sublime (or pyzo, if you must), and follow along line-by-line with this tutorial.
Additionally, here is his terminal tutorial if you'd like a quick refresher on some terminal navigation we'll be using.
What will I learn?
Great question! On a high level you'll learn the slimmed down version of how devices are connected over the internet and how instructions are communicated. Here is the wikipedia page if you want a more in-depth analysis.
Have you ever just wanted to mail memes to your relatives across the country? (Yes, that's mail, not email) Well Abhi has, and the process of sockets is preetttty much the same thing (if you squint hard enough)! Here is what happens when Abhi sends his edgy memes:
- Abhi finds a quality meme on Carnegie Mellon Memes for Spicy Teens and decides to send it to his extended family.
- He prints out the meme and sends it to the post office.
- The post office receives the letters,
- and sends them to the addresses of his relatives.
- Then, the relatives each receive the meme
- and laugh uncontrollably
Similarly, sockets is a way for computers to communicate and interact with each other. In python's implementation of sockets, multiple computers (clients) connect to a server, which facilitates (hosts) this communication. A typical sequence of sockets interaction looks like:
- A client triggers an action (such as moving).
- He/She/They sends a message to the server indicating what happened.
- The server receives the message,
- and sends the it back to all the clients.
- Then, each of the clients receives the message,
- and executes the command.
As you can see, there is a lot of communication happening--a lot can go wrong--so make sure you are thorough! With that said, lets get started with the tutorial!