Press "Enter" to skip to content

Python Socket Programming Tutorial



This socket programming tutorial will show you how to connect multiple clients to a server using python 3 sockets. It covers how to send messages from clients to server and from server to clients. I will also show you how to host your socket server locally or globally across the internet so anyone can connect. This uses the python 3 socket and threading module.

Code Download: https://techwithtim.net/tutorials/socket-programming/

⭐ Kite is a free AI-powered coding assistant for Python that will help you code smarter and faster. Integrates with Atom, PyCharm, VS Code, Sublime, Vim, and Spyder. I’ve been using Kite for 6 months and I love it! https://kite.com/download/?utm_medium=referral&utm_source=youtube&utm_campaign=techwithtim&utm_content=description-only

◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python
https://tech-with-tim.teachable.com/p/the-fundamentals-of-programming-with-python

📸 Instagram: https://www.instagram.com/tech_with_tim
🌎 Website https://techwithtim.net
📱 Twitter: https://twitter.com/TechWithTimm
⭐ Discord: https://discord.gg/pr2k55t
📝 LinkedIn: https://www.linkedin.com/in/tim-ruscica-82631b179/
📂 GitHub: https://github.com/techwithtim
🔊 Podcast: https://anchor.fm/tech-with-tim

💵 One-Time Donations: https://www.paypal.com/donate/?token=m_JfrPK7DsK4PLk0CxNnv4VPutjqSldorAmgQIQnMozUwwQw93vdul-yhU06IwAuig15uG&country.x=CA&locale.x=
💰 Patreon: https://www.patreon.com/techwithtim
◾◾◾◾◾◾

⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡

⭐ Tags ⭐
– Tech With Tim
– Python Tutorials
– Python Socket Programming
– Socket Programming Python
– Python Sockets Multiple Clients
– Socket Tutorial Python
– Python 3 Sockets

⭐ Hashtags ⭐
#python #sockets

0 0 vote
Article Rating
Subscribe
Notify of
guest
47 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Simon Thomas
Simon Thomas
1 month ago

Hi nice bit of coding but there is a number of errors in your networking description. Firstly the modem is not where your public address will sit it will be on the wan interface of the router and the router is in fact firewall as it will hide the private addresses behind the public address. You are dealing with tcp ports the is 65535 ports full list https://en.m.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers And the number you are seeing with the received message on the server is in fact the source port. Also you would not run your server on the modem it would be… Read more »

Michael Peres
Michael Peres
1 month ago

Thanks Tim, I'm now trying to make a simple message app. Thanks for the videos!!, it really helps me learn these different modules without reading the documentation.

Jeme
Jeme
1 month ago

This works better server than Ubisoft's servers…

Piyush Lakhani
Piyush Lakhani
1 month ago

Great Job Tim!!! ,
Love from Concordia University Library , Montreal

Ch Alwaz
Ch Alwaz
1 month ago

Thank you

Rohit Devaliya
Rohit Devaliya
1 month ago

Please, make a live stream on a 2d open world game using pygame.😊😊😊

JoshuaGonnaEatPizza
JoshuaGonnaEatPizza
1 month ago

35:00 In VSCode yes you can run multiple interpreters – in the terminal, you can plus +, and then the box next to the + to show both interpreters

Faiz Alam
Faiz Alam
1 month ago

SOCK_STREAM means tcp protocol by the way.

Devraj Ash
Devraj Ash
1 month ago

how to run django channels in 3.8python??

Quang Nguyễn
Quang Nguyễn
1 month ago

Hi Tim, can you tell me what software you use in 2:11? Thanks.

TC8
TC8
1 month ago

Using select is a good choice for asynchronous servers.

Ramanujan Nr
Ramanujan Nr
1 month ago

is it possible to connect two different operating systems using sockets?

Rekha Gujar
Rekha Gujar
1 month ago

Finally you choosen vscode

Haany Ali
Haany Ali
1 month ago

Awesome Intro!!!
Love your channel!

Miram
Miram
1 month ago

Awesome Tutorial, looking forward to part 2!

Devesh Shah
Devesh Shah
1 month ago

U clearly don't know much about sockets…

0 x 5 4 4 D
0 x 5 4 4 D
1 month ago

Thank you Tim ,i will just add some infos about making a public socket over the internet :– on the server side , you will have to add a new rule of type port being used to control connections for TCP / UDP .. mostly u will be using "tcp" in both the outbound and inbound rules.– probably run the scrip as admin just to avoid possible "Permission problems"– on the Client side u just gotta whitelist the client side program/app/script to allow all sending data over a tcp port .. else just go and add a rule as an… Read more »

Aditya Mahajan
Aditya Mahajan
1 month ago

We can add multiple terminals in VsCode (just if you are wondering) just click on the plus icon (beside 1: Python) where you will get the option. The video was extremely helpful, thanks 🤗

OneMadGypsy
OneMadGypsy
1 month ago

How do I give you 100 thumbs up? This was the perfect amount of info for a guy like me. I'm going to extend the snot out of this.

Cylinders truck
Cylinders truck
1 month ago

This is what I was looking for some days ago Now thanks to you.

Charles Starks, Jr
Charles Starks, Jr
1 month ago

Since you didn't know: 8 bytes can be a number up to 18 quintillion, or 18 with 18 zeros, which, when used as a header could represent a 18,000 Petabyte message. So a 64 Byte header is a bit overkill since it's 18 quintillion to the eighth power (6 x 10^57).

Programming with Tudor
Programming with Tudor
1 month ago

Cool tutorial

Keshav Mishra
Keshav Mishra
1 month ago

Getting an error while running the client.. Anyone knows how to solve this
Traceback (most recent call last):

File "client.py", line 13, in <module>

client.connect(ADDR)

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

Renmar Manlisis
Renmar Manlisis
1 month ago

This is so epic. Very helpful

sai anirudh
sai anirudh
1 month ago

TIM MY LAPTOP HAS i3 6th gen CAN IT HANDLE THIS LEVEL PROGRAMMING….BTW GREAT CONTENT

zed robot
zed robot
1 month ago

Could u plz make a tuto on pyqt5 python liberty

6447686C49474E686132556761584D675953427361575575
6447686C49474E686132556761584D675953427361575575
1 month ago

could also have used server = 127.0.0.1

LinkGT
LinkGT
1 month ago

Great tutorial. Recently learned how to deal with multi threading and created a chat app, and I can say socket programming is really cool.

Ivan Bezrukov
Ivan Bezrukov
1 month ago

Is it safe to open ports on your public IP though?

abimbola obadare
abimbola obadare
1 month ago

love the new intro tim. Boss mode activated

Max van Oord
Max van Oord
1 month ago

Covers perfectly the basics of sockets, good job!

Simple Analyst
Simple Analyst
1 month ago

Thankyou for your simple diagram/intro representing a public/private server – actually makes sense now. By any chance have you made a video covering what vscode extensions you use? Did a quick search of your channel and nothing appeared (keywords extensions vscode). P.S, I did play with kite but I honestly didn't like it. Thankyou.

Yoonsun Choi
Yoonsun Choi
1 month ago

Tim, you are so awesome and inspiring

Trishit Das
Trishit Das
1 month ago

Hi I am also making a python series in my channel for beginners annd for kids.check it out

pudny
pudny
1 month ago

thanks tim!

VM CHANNEL
VM CHANNEL
1 month ago

this was best
can you also make a video in subnetting execution

Pablo Bree
Pablo Bree
1 month ago

I can't belive you just uploaded this video. I'm studying sockets in C language at college and i'm struggling so bad. Wish to be able to work in python to solve my exercises!!! Btw.. Thank you so much, you have cleared so many doubts i got with sockts!! (Does this python code works between two Virtual Machines loaded with Ubuntu?)

super gmaer
super gmaer
1 month ago

i know thats ur private ip but stil dont show ur ip its stil bad

dv
dv
1 month ago

Hi Tim. Python is your main language, you will be make more videos about programming using python or you will be switch for example Java?

super gmaer
super gmaer
1 month ago

Hi how can i follow along without text editor

Sahaj
Sahaj
1 month ago

Hmm tbh not so good intro

Matheus Baumgarten
Matheus Baumgarten
1 month ago

Hey Tim! What about a series where you set up a server and client for like a chat or even a little game? A live stream day perhaps? Great content, keep it up!

Angel Pico
Angel Pico
1 month ago

This was a really good video Tim, look forward to part 2 !

Make Data Useful
Make Data Useful
1 month ago

Cool new intro Tim!

Mihhail Samusev
Mihhail Samusev
1 month ago

Thanks a lot! Please more tutorials about networking, you explain well!

Peter Goodman
Peter Goodman
1 month ago

Finally u using vs code.

Kumar Vaibhav
Kumar Vaibhav
1 month ago

I request you to please provide grpc tutorials also

47
0
Would love your thoughts, please comment.x
()
x