Python 3 Programming Tutorial - Sockets Binding and listening
Skills:
Python for Data70%
Key Takeaways
This video tutorial covers the basics of Python 3 programming with sockets, specifically binding and listening on a specific port. It demonstrates how to create a socket, bind it to a port, and listen for incoming connections using the socket library in Python 3.
Full Transcript
hello everybody and welcome to another Python 3 tutorial video with sockets so in the first video I showed you guys uh just the creation of a socket and using it to uh request some data uh then we did a port scanner then we combined threading and socket for a threaded socket or a threaded Port scanner rather um now we're going to go back to the purpose of sockets again again and we're going to be talking about sending and receiving data using sockets uh so with that let's go ahead and get started so I think um I'm just going to do one big control a and delete here um and then we'll go ahead and here we're going to import socket and then we're also going to import CIS for system now uh we're going to do a couple of things first we're going to say host and host is just going to be blank for now um it's sort of like arbitrary uh basically this just means that you're willing to accept um or it's going to be like all interfaces pretty much then Port we can specify any port that we want uh for this let's just do 5555 um you could put almost anything in there that you want but we'll be using 5555 so now what we want to do is we're going to say s equals socket. socket this should be pretty darn familiar by now socket. aore I oops unit in and then socket uh do sockor stream like that um again just the address family and sock stream uh so we can use the internet not UDP next um at this point we've created a socket now what we're ready to do is we want to bind this socket so let's say try s. bind and this has to be again uh two so we're going to say host and Port so we bind that and then um accept um and really the only exception we want to accept here is a socket error um accept socket error as e and then if we get that we're going to print string e so what was that error let's just print it out now at this point we've bound the socket and now what we can do is we can go s. listen and then in here you put a parameter we're going to put five and basically what this parameter does is it's it's kind of like a q or it is a Q and it's basically how many incoming connections will we fit into Q before we turn the connection away because we have too many um so that's what we're going to be doing so we're going to be listening um on Port uh 5,555 and now we will be able to make a connection um to it so uh let's do the following so we're going to go uh connection address equals s do accept and then we can actually go ahead and like we can print out some information on the connection so we can go like this we could say print connected to colon and we'll do plus uh addr for address zero and then we'll do another plus this will be okay there and then plus addr one and actually let's do string one and that should do it for us so now uh we should be able to run this first let's see if we get any error running it does not look like we did so we're running and we're waiting for a connection now what you can do is come over to your command. exe or if you're in bash and use the following commands so you could say tnet um and then Local Host 5555 hit enter and there might be a couple of can't speak couple of trouble for some of you guys um but first of all this worked we've it we've got the hey we made this connection first of all the connection is over at this point there was not really retaining any connection um but anyway you can see that we were able to make that connection it was listening and it connected and received some information from the person who connected to it now um if you're on Windows and you type tnet and it says tnet does not exist or that command is you know doesn't exist you go to uh you know Start Control Panel bring that down here you're going to want to go to programs and then over programs and features turn Windows features on or off click on that and then wait while this makes a list and come on down to tnet client you'll want to make sure that box tell not C tnet client is checked and then tnet will work on your machine similarly if you're on another machine um you know like if you're on Linux or something you might not have tet automatically installed so suseo app to get install telnet and then you'll be able to use telnet Okay so should cover it uh if you guys have any questions or comments uh getting this to work uh feel free to leave them below you it should be able to it should work for you as soon as you uh install tet um so anyways uh that's it as always thanks for watching thanks for all the support subscriptions and until the next video uh where we keep that connection open we do a little bit better uh listening and we do some cool stuff so stay tuned for that
Original Description
In this Python 3 and sockets tutorial, we cover how to bind and listen with sockets on a specific port.
Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/
Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M
Code from this video has been adapted, updated, and ported from Python 2.7 from: http://www.binarytides.com/python-socket-programming-tutorial/
http://seaofbtc.com
http://sentdex.com
http://hkinsley.com
https://twitter.com/sentdex
Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: Python for Data
View skill →Related Reads
📰
📰
📰
📰
How I Built a Free Online Image & PDF Processing Platform with Vue 3 + FastAPI
Dev.to · IAMUU
I Built a Free AI-Powered YouTube SEO Toolkit With Zero Budget. Here’s What Actually Happened.
Medium · Startup
How to Create a Second Version of Yourself Inside Obsidian Using AI (Step-by-Step Guide)
Medium · ChatGPT
How to prepare for Spain civil service TIC exam using AI in 2026
Dev.to · David García
🎓
Tutor Explanation
DeepCamp AI