The Art of Doing - Python Network Applications with Sockets

Video description

In this course, you will learn how to set up your own home network with static IP addresses and port forwarding so that anyone can access your programs over the Internet. Then you will learn how to set up a simple two-way chat in the terminal using the Socket module. Next, you will learn how to use the threading module to create a simple chat room in the terminal and how to use the Tkinter module to create a GUI chat room like the old AOL chat rooms.

Later, we will look at how to create an advanced GUI chat room with admin window using the JSON module, and finally, how to create your own online multiplayer game using the Pygame module.

As this is a project-based course, each project builds on the knowledge gained during the previous projects. In our culminating project, when we attempt to create our own online multiplayer game, we will be generating IPV4/TCP sockets to connect computers to a server running on a machine with a static IP and port forwarding enabled, creating various threads to run processes concurrently on our machines, we will use JSON to serialize python objects such as our game state and game players, and have a fully interactive GUI interface using Pygame.

By the end of this course, you will have multiple projects you can share with friends or family, have them run a client script from their house, connect to your server script, and show off all you learned.

What You Will Learn

  • Use the socket module to create a terminal-based two-way chat
  • Use the threading module to create a terminal-based chat room
  • Use a Tkinter module to make a GUI chat room
  • Configure router to allow communication from an external network
  • Use the JSON/Pickle modules to build an advanced GUI chat room with an admin window
  • Use the Pygame module to create an online multiplayer game

Audience

This intermediate course is intended for students with a basic understanding of Python and core programming concepts as well as comfort levels with both functional and object-oriented programming, as both will be used in the course's second half. Also, who is interested in learning how to write programs that can work over a network and communicate with one another.

Although it will be helpful to have prior knowledge of different Python modules, we will take the time to teach you everything you need to know to construct the program in this course.

About The Author

Michael Eramo: Michael Eramo is a life-long learner, a self-taught programmer, and an experienced educator. He holds official bachelor’s degrees in music, education, and physics and a master’s in mathematics. He is also a Microsoft certified software developer.

He has years of experience as a high school physics teacher, computer science teacher, and college mathematics teacher. He is a part of the New York State Master-Teacher Program, a network of more than 800 outstanding public-school teachers throughout the state who share a passion for STEM learning and for collaborating with colleagues to inspire the next generation of STEM leaders.

Table of contents

  1. Chapter 1 : Installation and Setup
    1. Course Preview
    2. Python Installation and Setup
    3. VS Code Installation
    4. Creating our Working Directory
    5. A Brief Overview of Networking Concepts
  2. Chapter 2 : Creating TCP and UDP Connections with the Socket Module
    1. Creating a TCP Server Socket
    2. Creating a TCP Client Socket
    3. Sending Data through a TCP Connection
    4. Creating and Sending Data through a UDP Server/Client
    5. Exploring the Buffer Size
    6. Basic Two-Way Chat Part 1 - Server/Client Setup
    7. Basic Two-Way Chat Part 2 - Enabling the Chat
  3. Chapter 3 : Creating a Terminal Chat Room with the Threading Module
    1. The Threading Module Basics Part 1
    2. The Threading Module Basics Part 2
    3. Terminal Chat Room Part 1 - Server/Client Setup
    4. Terminal Chat Room Part 2 - Adding Functionality
    5. Terminal Chat Room Part 3 - Adding Functionality
    6. Terminal Chat Room Part 4 - Adding Functionality and Testing
  4. Chapter 4 : Creating a Basic GUI Chat Room with the Tkinter Module
    1. The Tkinter Module – Defining a Root Window
    2. The Tkinter Module - Adding Frames
    3. The Tkinter Module - Adding Widgets
    4. The Tkinter - Module - Adding Functionality
    5. Basic GUI Chat Room Part 1 - Building the Client Layout
    6. Basic GUI Chat Room Part 2 - Building the Client Layout
    7. Basic GUI Chat Room Part 3 - Adding Functionality
    8. Basic GUI Chat Room Part 4 - Adding Functionality and Testing
  5. Chapter 5 : Creating an Advanced GUI Chat Room with the Json Module
    1. The Pickle Module - Sending Objects through the Data Stream
    2. The Json Module - Sending Objects through the Data Stream
    3. Advanced GUI Chat Room Part 1 - Updating the Client Layout
    4. Advanced GUI Chat Room Part 2 - Building the Server Layout
    5. Advanced GUI Chat Room Part 3 - Outlining Server Functionality
    6. Advanced GUI Chat Room Part 4 - Outlining Client Functionality
    7. Advanced GUI Chat Room Part 5 - Staring the Server
    8. Advanced GUI Chat Room Part 6- Processing Messages Server Side
    9. Advanced GUI Chat Room Part 7 - Starting the Client
    10. Advanced GUI Chat Room Part 8 - Sending Data from Client to Server.
    11. Advanced GUI Chat Room Part 9 - Adding Admin Functionality
    12. Advanced GUI Chat Room Part 10 - Adding Admin Functionality
    13. Advanced GUI Chat Room Part 11 - Final Testing
  6. Chapter 6 : Connecting to the Outside World
    1. Adjusting Host Firewall for LAN Communication
    2. Setting a Static IP Address for WAN Communication
    3. Enabling Port Forwarding for WAN Communication
    4. Testing out WAN Communication
    5. Configuring a Second Router...Different Settings!
  7. Chapter 7 : Creating a Multiplayer Game with the Pygame Module
    1. The Pygame Module - Creating a Game Window and Game Loop
    2. The Pygame Module - Setting Up a Game Class
    3. The Pygame Module - Setting Up a Player Class
    4. Using Fixed Length Headers - The Shortcomings of a Fixed Maximum Byte Size
    5. Using Fixed Length Headers - The Solution to our Problems
    6. Online Multiplayer Game Part 1 - Setting Up the Server
    7. Online Multiplayer Game Part 2 - Setting Up the Client
    8. Online Multiplayer Game Part 3 - Sending Pygame Configurations to the Client
    9. Online Multiplayer Game Part 4 - Creating a Player on the Server
    10. Online Multiplayer Game Part 5 - Sending the Player to the Client
    11. Online Multiplayer Game Part 6 - Starting the Game on the Server
    12. Online Multiplayer Game Part 7 - Starting the Game on All Clients
    13. Online Multiplayer Game Part 8 - Player Movement on the Client
    14. Online Multiplayer Game Part 9 - Creating a Game State on the Server
    15. Online Multiplayer Game Part 10 - Processing Game State on All Clients
    16. Online Multiplayer Game Part 11 - Resetting the Game for More Rounds
    17. Online Multiplayer Game Part 12 - Official Network Playtest!

Product information

  • Title: The Art of Doing - Python Network Applications with Sockets
  • Author(s): Michael Eramo
  • Release date: November 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781837631599