Python 3 Programming Tutorial – Sockets intro

In this Python 3 tutorial video, we cover the socket module. The socket module is a part of the standard library, so no installation is required. Sockets are an integral part for networking, but often confusing. I am by no means an expert on sockets, but I can at least share the knowledge I have on them.

Sample code for this basics series:

Python 3 Programming tutorial Playlist:

Code from this video has been adapted, updated, and ported from Python 2.7 from:

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6


Sk Nurul Islam says:

Hello Sir,
Can you please suggest me a book or full video series for Python socket programming…

Kari Abraham says:

THANK YOU!!!!!!!!

Vladislav Gorovenko says:

Thanks a lot for your video. I’m trying to pass the course called py4e now and on the way I’ve just stumbled across some difficulties to understand sockets and your video was a big help.

kuldeep master says:

what will request line do?

C N says:

ryan gosling is that u

hamed akbari says:

very good

Nicole Berger says:

I’d like to create a Python program that shuts down all devices on my network. (IP address space: [192,168,0,0], [192,168,255,255]) We only use Windows 7 and 10 each 64 BIT. – Who has three pupating children knows the reason … 😉

How can I change the code?

I have created the following program, but it does not work. Who can help me or write a better code?

There is the following error message:

ip = raw_input(“[[192,168,0,0],[192,168,255,255]]:”)
NameError: name ‘raw_input’ is not defined

Program Design:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

ip = raw_input(“[[192,168,0,0],[192,168,255,255]]:”)
nachricht = raw_input(“Nachricht: Jetzt ist Schlafenszeit”)

s.sendto(nachricht, (ip, 1))

if message == “shutdown” :
os.system(“shutdown -h now”)
else: print(“Gute Nacht”)

Who have a better idea?

Yeshwanth Allampati says:

Hey SentDex! I have just finished your Python Basics Playlist! I have been learning from it since almost 3 days. Thanks a lot! Your explanation is simply unbelievable! I know the whole basics of python today and that’s solely because of you.


aayush sarna says:

What does this line means? s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) What does this syntax means “socket.socket()” and socket.AF_INIT? Can’t we use just AF_INIT and Stream as parameter?

Abinay Gangireddygari says:

what kind of difference does it make to use urllib and socket module anyway?

Ian Parker says:

port 20, wat?

Vivek Teega says:

Man, you are AWESOME!! I spent the last 6 hours trying to figure out something related to sockets and this tutorial just cleared everything <3

Zero Nairo says:

mfw ftp is on 21 not 20

Ali Umair says:

you room is more organized than my life

Ali Basharat says:

Hey sentdex, I want real-time communication between a Raspberry pi device and Android application.
What should I do?
Please share your knowledge.

Behnam Anisi says:

bro you will you use 21 first then use port 20 for connection to FTP .

AL3X BLUME says:

Sentdex i need your gmail username for a tool that I coded for you I hope you will enjoy it

وسام السراج says:

I think the best way to get an IP address or using other words to resolve the server name using CMD is by using NSLOOKUP

geek programmer says:

why did u add “‘nn” in request ?

Sergio Brun says:

hi! great tutorial series. I run the code but didnt get the same output, I got this
b’HTTP/1.1 505 HTTP Version Not Supportedrnconnection: closernserver: nginxrndate: Mon, 12 Mar 2018 20:27:23 GMTrncontent-length: 0rnrn’

why is this happening?

Devilspawn RSPS says:

you’re a hell of a funny person xD

hunar omer says:

All i heared was (suck it)

NoCraft Games says:

I love your tutorials so much, very informative and an effective way to learn. keep it up man

abubakkar tahir says:

Hello sentdex thank,s for making this series can you make real chat application in python through which sender can send text and image like skype

DerTim says:

Hey I need some help! I want to write a private pyradio with sockets but I don’t know how to stream it. Could you help me?

AL3X BLUME says:

I have the tool ready just give me the email address i promise this code is not scam code

Progress says:

You are such a nice guy, you are giving us free course. Thanks 🙂

 Write a comment


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!