Sockets Tutorial with Python 3 part 1 - sending and receiving data

  Рет қаралды 803,372

sentdex

sentdex

5 жыл бұрын

Welcome to a tutorial on sockets with Python 3. We have a lot to cover, so let's just jump right in. The socket library is a part of the standard library, so you already have it.
Source code and text-based tutorial: pythonprogramming.net/sockets...
Channel membership: / @sentdex
Discord: / discord
Support the content: pythonprogramming.net/support...
Twitter: / sentdex
Facebook: / pythonprogramming.net
Twitch: / sentdex
G+: plus.google.com/+sentdex
#sockets #python #tutorial

Пікірлер: 629
@grim1427
@grim1427 3 жыл бұрын
That feeling when you spend hours weeding through needlessly complicated tutorials until you find the one that just makes sense and is 1000 times simpler than any of the others.
@og_yamiatan3957
@og_yamiatan3957 2 жыл бұрын
:) i cant found where to download THIS python all it does it opens CMD
@michaelcarnevale5620
@michaelcarnevale5620 Жыл бұрын
srs just show me and tell me what it does lol
@omarromero9038
@omarromero9038 2 жыл бұрын
Since I found your videos, I've been hooked on Python and eventually branched out and lost sight of your videos. After watching this video, today, I'm reminded why your videos are by far better than most other tutorials.
@wi1h
@wi1h 5 жыл бұрын
AF_INET means Address Family InterNET for IPV4. IPV6 is AF_INET6, Bluetooth is AF_BLUETOOTH, unix sockets are AF_UNIX, etc.
@sentdex
@sentdex 5 жыл бұрын
Right, I got that. Wondering where the AF and INET is coming from.
@sripadkarthik9081
@sripadkarthik9081 4 жыл бұрын
Tanq @wi l
@rodricbr
@rodricbr 3 жыл бұрын
that's very useful, thanks
@anirudhpuranik5222
@anirudhpuranik5222 4 жыл бұрын
This is by far the most easily understandable python socket tutorial I've come across! It's like a ray of hope while I'm doing my final year project.
@robertkraciuk2753
@robertkraciuk2753 5 жыл бұрын
right on time my man, just when i started looking for sockets tutorials right on goddamn time, love it !
@RyuWeiWei
@RyuWeiWei 4 жыл бұрын
A class and practice of 2 hrs. Explained within 15min with making so much sense. I like it.
@freakyshine
@freakyshine Жыл бұрын
The way you explain it really shows you understand the topic. Love to see that in a tutorial because it means it's a good tutorial.
@hanac5586
@hanac5586 Жыл бұрын
I really like your teaching style, explaining every line briefly, makes things a lot clearer. Thank you!
@oliverli9630
@oliverli9630 5 жыл бұрын
while i was looking for socket tutorials, there it is! lovely! added to favorite for later use. really useful in trading.
@RohitAwate
@RohitAwate 5 жыл бұрын
I recently wrote similar socket code in C, and its interesting how closely Python and C map here. AF stands for address family. It denotes the kind of addresses a socket can communicate with. In this case, the socket uses IPv4 addressing. Similar families are AF_INET6 for IPv6, AF_UNIX for IPC on Unix systems, AF_BLUETOOTH for Bluetooth and so on.
@MDJ5
@MDJ5 5 жыл бұрын
Ah! So AF_INET is kind of the standard way of expressing it much in the way no one says 'hey whats your IPv4 address?' when anyone would know what you mean by saying just 'ip address'. Is that right?
@RohitAwate
@RohitAwate 5 жыл бұрын
@@MDJ5 Yep, that makes sense.
@billscott356
@billscott356 4 жыл бұрын
@@RohitAwate Additionally the AF_INET family identifier predated the existence of IPv6 by many, many years. As such it wasn't called something like AF_INET4. The address family value is taken directly out of the C library as it is indeed the C library that is used underneath Python to create the socket. This scheme pops up in lots of places across Python.
@bonbonpony
@bonbonpony 4 жыл бұрын
@@billscott356 Yup, Python's version is basically a wrapper for BSD Sockets from C. However, when I look at that IPv4 thing, it makes me wonder: what did the previous versions of IP protocol look like? Because if we have IPv.4 and IPv.6, there must have been IPv.1, 2 and 3 some time in the past, right? :q
@altimmons
@altimmons 3 жыл бұрын
@@bonbonpony yes came here to say this. Python sockets is just a rather thin (and better worded) wrapper for
@jeremytoledano123
@jeremytoledano123 3 жыл бұрын
Dude, i see a lot of tutorials dealing with socket programming, by far it is the best! Clear, Sharp, Smart!
@mazhai2006
@mazhai2006 3 жыл бұрын
I have been playing with python programming for a few weeks as part of self learning. Socket programming felt bit troublesome and I always had issues when running. Came upon your video above and tried the way you showed above and i made connection. hurray!!. I am in socket programming. great feeling. thanks man
@abhinavghosh725
@abhinavghosh725 5 жыл бұрын
GREAT VIDEO MAN!! FOLLOWING YOUR SERIES FROM PYTHON BASICS TO ML TO DATA SCIENCE AND NOW THIS!!!KEEP DOING THE GOOD WORK!!! ! BLESS YOU!!
@1944GPW
@1944GPW 4 жыл бұрын
Full marks to you for using a nice big font to make the code clearly easy to read on KZfaq. You would not believe how many coding examples make you have to squint to figure out what they were typing ...or maybe you would. Thanks again, nice presentation.
@kostadingramatikov9692
@kostadingramatikov9692 3 жыл бұрын
I've been looking for good tutorials no this subject and couldn't find any, untill you came!! Great tutorial, great teaching skills. Instantlly subscribed!!!
@pythonbibye
@pythonbibye 3 жыл бұрын
This was so absolutely helpful!! Thank you so much and keep up with the good work!! I really love your tutorials
@paulstaley4245
@paulstaley4245 4 жыл бұрын
Very entertaining video. I am still very new to python and I've been writing some basic scripts for work. This video is exactly what I was looking for. Thank you!
@izaquemiguelgabriel
@izaquemiguelgabriel 4 жыл бұрын
That’s exactly what I was looking for! Thanks, sir!
@akay4670
@akay4670 5 жыл бұрын
Thanks man! Waiting for the next video. Learn alot from your tutorials, commenting for the 1st time on any youtube video.
@sentdex
@sentdex 5 жыл бұрын
I am honored!
@ShalabhBhatnagar-vn4he
@ShalabhBhatnagar-vn4he 4 жыл бұрын
Simple and elegant, master orator and Python maestro... (and that cup is so unique)
@ai.simplified..
@ai.simplified.. 3 жыл бұрын
Sentdex, you r every where in python learning clips Thx, for your valuable time &effort to educate us You r my hero brow😍
@lightEuphoria
@lightEuphoria Жыл бұрын
One of the best tutorials on Yotube. Thank you so much for such a great and enthusiastic explanation! It all finally works
@rahul5794
@rahul5794 5 жыл бұрын
I was actually waiting for this tut. I couldn't find anything that I could understand. Thanks alot! I'll watch it right away!
@sentdex
@sentdex 5 жыл бұрын
Hopefully you will be able to follow this one! Ask questions if lost!
@rahul5794
@rahul5794 5 жыл бұрын
@@sentdex I loved it. This served as a great basis to understand sockets. I am really looking forward to the next part. Cheers ❤️
@raiyanyahya
@raiyanyahya 5 жыл бұрын
Great video Sentdex .. thank you for the effort !!
@SmashPhysical
@SmashPhysical 3 жыл бұрын
Was looking for something straightforward on this topic, thanks!
@Kefford666
@Kefford666 3 жыл бұрын
Man your videos are so helpful, and Python is just too fun! ❤️
@Zackyzic
@Zackyzic 5 жыл бұрын
Thanks for this! Are you planning on making a full "network programming with python" series? I've been interested in learning more about this but never really found a good jumping off point, and as a back-end web developer, I want to learn more about the hardware/software interfaces I'm working with. Your videos are really good and I love the work you're doing!
@12Edix21
@12Edix21 5 жыл бұрын
Hi dex! Love your tutorials! Is there any chance you would make an updated threading tutorial? The sockets library goes very well together with threading functionality.
@timandmel777
@timandmel777 4 жыл бұрын
Hi sentdex. Good tutorial, it get's to the point quickly without painfully explaining the history and the why and on and on. Just enough background and just get to it! I like it. Just one note. I know this works for a tutorial purpose, but when you concatenate a string with += in a loop, it's dangerous. If this were a very large amount of text, the stack memory could exhaust. This is because strings are immutable and so each loop, it creates another copy of the string plus the added part each loop. In a fast loop with many iterations, the python garbage collection will not have enough time to release the memory for the previous copies and run out of stack memory. It is good Python practice to not use that method in a loop. Rather, append to a list of strings in the loop, then join them together at the end. Just a word of caution for those who may want to scale something like this up.
@hamadaag5659
@hamadaag5659 4 жыл бұрын
“And then an exclamation mark because this is serious business” I laughed my pants off hearing that😂
@TheFarmacySeedsNetwork
@TheFarmacySeedsNetwork Жыл бұрын
Thanks! Moving to the next video... Appreciate the in-depth explanations. Some stuff I know.. some I am clueless.. those clues are critical! :)
@garcand
@garcand 3 жыл бұрын
Thank you for helping me with my first python project. Creating a socket :)
@ahmdzamir8218
@ahmdzamir8218 2 жыл бұрын
Thankyou so much for this tutorial!
@pl1365
@pl1365 5 жыл бұрын
thanks a lot,man!It is super helpful. You are really a life savior to me!
@Lucifer-wd7gh
@Lucifer-wd7gh 3 жыл бұрын
I love how he smile everytime 😀 👍
@nestorbongiorno1342
@nestorbongiorno1342 3 жыл бұрын
Excellent explanation! Thank you!
@KoN312
@KoN312 3 жыл бұрын
Really helped.me understand. I was doing some trying wirh tcp connections and sending data... you opened my eyes for what i was doing wrong.. definetly a sub 👍
@JohnBrian-zs5yp
@JohnBrian-zs5yp Жыл бұрын
Amazing tutorial, thanks man
@swiftlyexplained703
@swiftlyexplained703 3 жыл бұрын
Awesome tutorial! Thanks!
@paulcopeland4446
@paulcopeland4446 3 жыл бұрын
Oh man, perfect explainer. Thanks!
@ShalabhBhatnagar-vn4he
@ShalabhBhatnagar-vn4he 4 жыл бұрын
Master class by the masterclass! Thanks!
@danz5476
@danz5476 2 жыл бұрын
THE BEST cup I saw in my life !
@alexchege2271
@alexchege2271 4 жыл бұрын
Excellent one. Love it
@sudeep.g
@sudeep.g 5 жыл бұрын
Love it! Exactly what I needed
@sentdex
@sentdex 5 жыл бұрын
Great!
@anigraytion7987
@anigraytion7987 4 жыл бұрын
So is this: kzfaq.info/get/bejne/mtV1pLiZq8-1g2g.html
@longphamthanh2010
@longphamthanh2010 Жыл бұрын
Short and very impact video, really good for beginner like me.
@danverzhao9912
@danverzhao9912 2 жыл бұрын
Incredible, this is very clear
@sistematico17
@sistematico17 2 жыл бұрын
you are an amazing educator! thank you
@JoshxDude92
@JoshxDude92 3 жыл бұрын
Dude, super helpful. Thanks!
@jayh5992
@jayh5992 4 жыл бұрын
Quick note, I think often you first send the size kf the message as a fixed amount of bytes, so you can have a variable message length later. Just using a fixed buffer either requires you to pad the message or you will receive multiple messages in one recv call when the calls are coming in fast enough
@suprecam9880
@suprecam9880 3 жыл бұрын
bro thank you for the tutorials. helping me out a lot putting this all into regular people speak lol
@man.h
@man.h 5 жыл бұрын
Thank you soooooo much.! All best from Germany
@sentdex
@sentdex 5 жыл бұрын
You're welcome!
@pafnutiytheartist
@pafnutiytheartist 5 жыл бұрын
Thank you for this tutorial, i tried to use sockets in python a while back and got quite confused at first.
@megha7243
@megha7243 3 жыл бұрын
wow! that was interesting. Thank you
@NamasivayamC
@NamasivayamC 4 жыл бұрын
Really appreciate your work and video
@user-tl8ny2jk7h
@user-tl8ny2jk7h 3 жыл бұрын
this video was amazing! thank you
@jerylin1491
@jerylin1491 3 жыл бұрын
This is very helpful, huge thanks
@seanshimon
@seanshimon 2 ай бұрын
`socket`: This is the module in Python that provides access to the BSD socket interface. It is used to create networking applications. `AF`: Stands for "Address Family". It specifies the format of the address. In this case, `AF_INET` indicates the IPv4 address family. `INET`: Stands for "Internet". This indicates that the addresses are IPv4 addresses, which are used for internet protocol version 4.
@Klungklung123
@Klungklung123 Жыл бұрын
your the best youtuber i understud immediatly other than by other youtubers you r explaining very well
@SoumilShah
@SoumilShah 5 жыл бұрын
finally tutorial i wanted great
@anigraytion7987
@anigraytion7987 4 жыл бұрын
Here is another tutorial from him i recommend then: kzfaq.info/get/bejne/mtV1pLiZq8-1g2g.html
@AbhishekKumar-mq1tt
@AbhishekKumar-mq1tt 5 жыл бұрын
Thank u for this awesome video
@user-cc8kb
@user-cc8kb 2 жыл бұрын
cool tutorial! thank you very much :)
@PascalThalmann
@PascalThalmann 4 жыл бұрын
Excellent explanation. Thx
@emilypark8144
@emilypark8144 4 жыл бұрын
thank you sooooooo much!! you are the best Python teacher :)
@mohammadespahrom3295
@mohammadespahrom3295 3 жыл бұрын
Excellent training video good job !!!!
@windyruss
@windyruss 3 жыл бұрын
awesome mug!
@yassinemessaoudi
@yassinemessaoudi 5 жыл бұрын
Great tuto i really need that ! thank you !
@sentdex
@sentdex 5 жыл бұрын
Happy to make em!
@leomanangka1957
@leomanangka1957 4 жыл бұрын
This what i need for my robotic project, thanks
@OliverHext
@OliverHext 3 жыл бұрын
Nice video. Clearly explained
@user-ln2qr5mn8r
@user-ln2qr5mn8r 5 жыл бұрын
That mug made my day!
@anigraytion7987
@anigraytion7987 4 жыл бұрын
So will this: kzfaq.info/get/bejne/mtV1pLiZq8-1g2g.html
@h_wavey7006
@h_wavey7006 5 жыл бұрын
Thank you so much, you just helped with my project to do with an encrypted messaging app - seriously needed to learn this and there's no man I'd rather learn it from.
@carlosedubarreto
@carlosedubarreto 3 жыл бұрын
Amazing explanations!!!!!
@marcelolopesdeamorimjunior9723
@marcelolopesdeamorimjunior9723 3 жыл бұрын
Yesir! Great material
@nav400
@nav400 5 жыл бұрын
hyped on this one.
@anigraytion7987
@anigraytion7987 4 жыл бұрын
You should be hyped on this one then: kzfaq.info/get/bejne/mtV1pLiZq8-1g2g.html
@ClaudioNarra
@ClaudioNarra 2 жыл бұрын
thank you very much !!
@KenanArik
@KenanArik 4 жыл бұрын
Love the mug!
@anigraytion7987
@anigraytion7987 4 жыл бұрын
Then you should love this! kzfaq.info/get/bejne/mtV1pLiZq8-1g2g.html
@gregoryfenn1462
@gregoryfenn1462 3 жыл бұрын
999k subs, you’re sooo close!
@chief6685
@chief6685 4 жыл бұрын
Thanks for the sockets work describe
@slonbeskonechen8310
@slonbeskonechen8310 3 жыл бұрын
GREAT, GREAT THANK YOU!!!!
@FoX84tac022
@FoX84tac022 3 жыл бұрын
If I'm not mistaken, then 1024 is the packet size. I think this will vary depending on what your network can handle (i.e. jumbo frames). You can test if you can send/receive a specific size packet by using *ping -l [size] [address]* - The *l* is a lowercase L
@equiposdecalor8077
@equiposdecalor8077 5 жыл бұрын
Thanks Bro your video helped me to finish my code
@biology789
@biology789 Жыл бұрын
the AF_INET constant is used to specify the address family for IPv4 sockets. AF stands for "Address Family", and INET stands for "Internet Protocol version 4".
@coddr4778
@coddr4778 3 жыл бұрын
Are you an god??? you can prgramming really gooood , dont stop with this :)
@trampflips101
@trampflips101 4 жыл бұрын
4:00 I may be mistaken but i'm pretty sure it makes sense to use clientsocket.send() (and not s.send() or s.send(clientsocket)) because s is the welcoming socket only. By that I mean clients request to connect via that socket, but they don't actually connect to it, we make a new one (clientsocket) specifically for them, and that's what they connect to. So clientsocket and s are both sockets on the server side that are both bound to the same port, it's just s is used for setting up connections whilst clientsockets are used for making the actual connections.
@azzakialjaylani7679
@azzakialjaylani7679 4 жыл бұрын
I am new subscriber, but i found your lessons very useful. Thank you.
@anigraytion7987
@anigraytion7987 4 жыл бұрын
Here is another one i recommend: kzfaq.info/get/bejne/mtV1pLiZq8-1g2g.html
@MrFlipflops4
@MrFlipflops4 3 жыл бұрын
This guy is the man!!
@BARaaz04
@BARaaz04 5 жыл бұрын
Hi, accept() function creates a brand new socket that is used to send and receive data. That way the socket object "s" that you created at the beginning is used to receive the request from multiple clients. If you use socket object "s" to send and receive data that you cannot handle multiple clients at the same time. That's why the new socket obtained by calling accept() is used to send and receive data.
@fordorth
@fordorth Жыл бұрын
i love your coffee cup!
@erikpalacios7238
@erikpalacios7238 3 жыл бұрын
Thanks!!!! you´re awesome!!!!
@learntocode5464
@learntocode5464 3 жыл бұрын
Cool , thanks
@dandapanidas351
@dandapanidas351 4 жыл бұрын
very nice video for socket programming in python
@luccaviccini8787
@luccaviccini8787 5 жыл бұрын
Loved the video!!! Please do one for UDP connection!!
@divyaprakashks4789
@divyaprakashks4789 4 жыл бұрын
thanks a lot man
@Khan-pj2on
@Khan-pj2on 2 жыл бұрын
cool mug!!!
@academicpreparation8497
@academicpreparation8497 5 жыл бұрын
Hey Bro, you are my inspiration.....:-)
@benjaminbenjamin8834
@benjaminbenjamin8834 2 жыл бұрын
Amazing...........This guy is AWESOME!
@salimsalim-wv1dm
@salimsalim-wv1dm 5 жыл бұрын
The best Channel From Morocco BigUp
@sentdex
@sentdex 5 жыл бұрын
Thanks!
@rafy-ivanmorales3077
@rafy-ivanmorales3077 2 жыл бұрын
I'm a new student trying to learn, so I can become a programmer with python and I have a project on how to make a port scan. So far I already make a port scan with Python3, and it scans fine, give a date and everything working good so far. I see on your video tutorial you give example on how to send and receiving data. I would like to ask for your advice if you can and guide me on how I will add this 3 in a Python script, I have: 2. System should look for all the ports between the range of 1 to 1025 3. If the Ports is open, it should create a file and add an entry for port number 4. In case of any exception for instance “host is not available”, “host name could not be resolved” or due to any other error, you need to write that exception into the same file. Thank you and Merry Christmas.
@Raj_Patel21
@Raj_Patel21 5 жыл бұрын
After doing socket programming in Java this seems very elegant.
@bonbonpony
@bonbonpony 4 жыл бұрын
Then I'm scared to ask how Java handles this :s
@souhaillepacifique7572
@souhaillepacifique7572 2 жыл бұрын
thank you , so much usefull
@JerettFranklin
@JerettFranklin 4 жыл бұрын
¡Gracias por la lección!
Python Sockets Simply Explained
39:33
NeuralNine
Рет қаралды 155 М.
ОДИН ДЕНЬ ИЗ ДЕТСТВА❤️ #shorts
00:59
BATEK_OFFICIAL
Рет қаралды 8 МЛН
🌊Насколько Глубокий Океан ? #shorts
00:42
FOOLED THE GUARD🤢
00:54
INO
Рет қаралды 63 МЛН
Websockets in Python
17:52
APMonitor.com
Рет қаралды 27 М.
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 369 М.
TCP vs UDP Sockets in Python
17:43
NeuralNine
Рет қаралды 30 М.
Let's Settle This! What Wrench & Socket Design Will Slip 1st?
13:55
Torque Test Channel
Рет қаралды 2,6 МЛН
every good programmer should know how to code this data structure (its easy)
21:08
File Transfer via Sockets in Python
14:44
NeuralNine
Рет қаралды 56 М.
Creating a Simple Socket Server and Client in Python
15:44
Real Python
Рет қаралды 15 М.
Socket Programming Using Python
17:07
Telusko
Рет қаралды 288 М.
ОДИН ДЕНЬ ИЗ ДЕТСТВА❤️ #shorts
00:59
BATEK_OFFICIAL
Рет қаралды 8 МЛН