Best Way to Learn Python in 2020 : Episode 4

By now you should be very comfortable writing Python code that runs on a single machine.

But what if you want to write code that communicates with other machines over a network?

If you want to do that, then you are going  need  learn about socket programming in python in episode.

And for that I highly recommend you learn about the basics of computer networks first. Here’s my favorite book.

After you learn the basic networking concepts, you can use Python’s libraries to write code on one machine that communicates with code on another.

It’s like magic. I still remember the exhilaration I felt the first time I had two laptops communicating back and forth to each other over a Wifi network.

Follow these three steps to get started.

Step 1: Write an Echo Program

In this step, you will use Python’s socket module to write a simple TCP server on one machine and a TCP client on another.

Make sure they are two different computers and that both of them are connected to your home network.

The idea of the Echo program is simple. The client-side reads a message from the user and sends this message to the server over the network.

At the server-side, when this message is received, the server echoes the same message back to the client.

Think of the Echo program as the Hello World program but for socket programming.

After that, you can move on to more complex programs.

Step 2: Play around with HTTP

Once you’re comfortable with writing simple TCP client-server applications, you can start using Python’s requests module to send and receive HTTP messages.

This is especially useful because the vast majority of web services these days provide an HTTP API interface that you can interact with programmatically. For example, FacebookTwitter, and Google maps all have HTTP API interfaces that your code can communicate with.

And if you feel a little more adventurous and want to take this a bit further, you can also scrape the web with BeautifulSoup.

Step 3: Know thy tools

Like any other program, sometimes when you write a networking program, your program will not work from the first attempt.

However, debugging networking programs is a little different than debugging regular programs.

That’s why you need to equip yourself with the tools necessary to troubleshoot what’s going on.

Here are some of the most popular networking tools that you will need.

ping is used to check the connectivity between your machine and another one.

netstat is a versatile networking tool that allows you to, among other things, monitor network connections both incoming and outgoing.

tcpdump is one of my favorite tools for learning networks. It tools allows you to listen to, capture, and analyze real packets going into and out of your computer through any network interface.

Wireshark is a nice GUI interface that does pretty much everything that tcpdump can do. I recommend starting out with Wireshark before moving on to tcpdump just because it’s a little more user-friendly.

And like I said, to understand what all these Get, SYNSYN ACKFIN mean you need to learn networking fundamentals first.

Hope you guys enjoyed this episode!!

Comments

Popular posts from this blog

Best Way to Learn Flutter (2020 Step-by-Step Guide) : Episode 2

Best Way to Learn Python in 2020 : Episode 2