Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Socket Programming in Python Part 1: Handling Connections (Overview)

Sockets and the socket API are used to send messages across a network. They provide a form of inter-process communication (IPC). The network can be a logical, local network to the computer, or one that’s physically connected to an external network, with its own connections to other networks. The obvious example is the Internet, which you connect to with your ISP.

In this two-part series, you’ll create:

  • A simple socket server and client
  • An improved version that handles multiple connections simultaneously
  • A server-client application that functions like a full-fledged socket application, complete with its own custom header and content

By the end of part one, you’ll understand how to use the main functions and methods in Python’s socket module to write your own client-server applications, including ones with multiple connections. In part two, you’ll dive into building a custom class and handling errors.

Download

Sample Code (.zip)

2.8 KB
Download

Course Slides (.pdf)

2.1 MB

00:00 Hello, and welcome to this two-part course on using socket programming in Python. This is a look inside how information is exchanged between programs on the Internet.

00:11 It will definitely help you in writing web and other Internet applications. In this first part of the course, you’ll learn about the basics of establishing connections between two computers.

00:21 Then in part two, you’ll study a simple but full application. This course begins with some background about the Internet, then you’ll see code used to create connections.

00:33 and finally look at code that can handle multiple connections.

00:38 Sockets are the pathways programs use to send messages from one computer to another. You’ll see how that’s done through much of the functionality of the socket API, and you’ll see how they form a type of interprocess communication, whether it’s between different processes on the same computer, or over a network.

00:58 This course is based on a tutorial guide by Nathan Jennings. You can find it and other materials on sockets at realpython.com.

01:08 After completing this course, you will know how to write code to create and use sockets, create a simple client/server program, and how to expand that program to allow for multiple connections.

01:25 Let me tell you about the tools I’ll be using in this course. For Python program files, I use Visual Studio Code with the Dark+ theme. My terminal shell is iTerm2 for macOS. And for my REPL, I use ptpython with its native theme.

01:43 All of the program files you’ll see are available at the link below. I’m Howard Francis, and I’m excited to lead you through this course on Socket Programming in Python. So let’s begin.

Become a Member to join the conversation.