No video

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

  Рет қаралды 808,224

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

Пікірлер: 633
@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 3 жыл бұрын
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.
@jeremytoledano123
@jeremytoledano123 3 жыл бұрын
Dude, i see a lot of tutorials dealing with socket programming, by far it is the best! Clear, Sharp, Smart!
@1944GPW
@1944GPW 5 жыл бұрын
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.
@hanac5586
@hanac5586 Жыл бұрын
I really like your teaching style, explaining every line briefly, makes things a lot clearer. Thank you!
@freakyshine
@freakyshine 2 жыл бұрын
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.
@RyuWeiWei
@RyuWeiWei 4 жыл бұрын
A class and practice of 2 hrs. Explained within 15min with making so much sense. I like it.
@seanshimon
@seanshimon 3 ай бұрын
`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.
@pythonbibye
@pythonbibye 3 жыл бұрын
This was so absolutely helpful!! Thank you so much and keep up with the good work!! I really love your tutorials
@robertkraciuk2753
@robertkraciuk2753 5 жыл бұрын
right on time my man, just when i started looking for sockets tutorials right on goddamn time, love it !
@oliverli9630
@oliverli9630 5 жыл бұрын
while i was looking for socket tutorials, there it is! lovely! added to favorite for later use. really useful in trading.
@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
@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 5 жыл бұрын
@@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
@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!!!
@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!!
@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!
@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
@ShalabhBhatnagar-vn4he
@ShalabhBhatnagar-vn4he 4 жыл бұрын
Simple and elegant, master orator and Python maestro... (and that cup is so unique)
@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!
@hamadaag5659
@hamadaag5659 4 жыл бұрын
“And then an exclamation mark because this is serious business” I laughed my pants off hearing that😂
@Assyrian_man
@Assyrian_man 14 күн бұрын
Me too hahaha
@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.
@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!
@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 ❤️
@izaquemiguelgabriel
@izaquemiguelgabriel 4 жыл бұрын
That’s exactly what I was looking for! Thanks, sir!
@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! :)
@suprecam9880
@suprecam9880 3 жыл бұрын
bro thank you for the tutorials. helping me out a lot putting this all into regular people speak lol
@Kefford666
@Kefford666 4 жыл бұрын
Man your videos are so helpful, and Python is just too fun! ❤️
@SmashPhysical
@SmashPhysical 3 жыл бұрын
Was looking for something straightforward on this topic, thanks!
@raiyanyahya
@raiyanyahya 5 жыл бұрын
Great video Sentdex .. thank you for the effort !!
@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 👍
@Klungklung123
@Klungklung123 Жыл бұрын
your the best youtuber i understud immediatly other than by other youtubers you r explaining very well
@garcand
@garcand 3 жыл бұрын
Thank you for helping me with my first python project. Creating a socket :)
@pafnutiytheartist
@pafnutiytheartist 5 жыл бұрын
Thank you for this tutorial, i tried to use sockets in python a while back and got quite confused at first.
@pl1365
@pl1365 5 жыл бұрын
thanks a lot,man!It is super helpful. You are really a life savior to me!
@Lucifer-wd7gh
@Lucifer-wd7gh 4 жыл бұрын
I love how he smile everytime 😀 👍
@coddr4778
@coddr4778 3 жыл бұрын
Are you an god??? you can prgramming really gooood , dont stop with this :)
@longphamthanh2010
@longphamthanh2010 Жыл бұрын
Short and very impact video, really good for beginner like me.
@ahmdzamir8218
@ahmdzamir8218 2 жыл бұрын
Thankyou so much for this tutorial!
@jayh5992
@jayh5992 5 жыл бұрын
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
@danz5476
@danz5476 2 жыл бұрын
THE BEST cup I saw in my life !
@emilypark8144
@emilypark8144 4 жыл бұрын
thank you sooooooo much!! you are the best Python teacher :)
@man.h
@man.h 5 жыл бұрын
Thank you soooooo much.! All best from Germany
@sentdex
@sentdex 5 жыл бұрын
You're welcome!
@JohnBrian-zs5yp
@JohnBrian-zs5yp Жыл бұрын
Amazing tutorial, thanks man
@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.
@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
@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
@SafikMaster
@SafikMaster 4 жыл бұрын
12:38 My code is exactly the same, yet the message that I receive is only "erver!" instead of "Welcome to the server!". It seems as if it's not buffering correctly. How can I fix that?
@iliqnew
@iliqnew 5 жыл бұрын
Hi there! Thanks to you I was able to make a server-client(s) connection on my own. But I struggle finding a way to make the communication between the two along 2 or more distant computers. Can you PLEASE show us how to do this without buying hosting or domain? Honestly, I would be your top fan if you do this
@paulcopeland4446
@paulcopeland4446 3 жыл бұрын
Oh man, perfect explainer. Thanks!
@JorgeMartinez-zg1wj
@JorgeMartinez-zg1wj 4 жыл бұрын
I don't understand how your code ever gets to if len(msg)
@megha7243
@megha7243 3 жыл бұрын
wow! that was interesting. Thank you
@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
@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.
@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
@sistematico17
@sistematico17 2 жыл бұрын
you are an amazing educator! thank you
@academicpreparation8497
@academicpreparation8497 5 жыл бұрын
Hey Bro, you are my inspiration.....:-)
@nestorbongiorno1342
@nestorbongiorno1342 3 жыл бұрын
Excellent explanation! Thank you!
@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.
@ShalabhBhatnagar-vn4he
@ShalabhBhatnagar-vn4he 4 жыл бұрын
Master class by the masterclass! 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.
@user-cc8kb
@user-cc8kb 2 жыл бұрын
cool tutorial! thank you very much :)
@FoX84tac022
@FoX84tac022 4 жыл бұрын
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
@gregoryfenn1462
@gregoryfenn1462 3 жыл бұрын
999k subs, you’re sooo close!
@paul100plus2
@paul100plus2 4 жыл бұрын
Very nice Video, it is a good tutorial!!! PS: I am sorry about mistakes in this text, I am from Germany.
@fordorth
@fordorth Жыл бұрын
i love your coffee cup!
@JoshxDude92
@JoshxDude92 3 жыл бұрын
Dude, super helpful. Thanks!
@swiftlyexplained703
@swiftlyexplained703 4 жыл бұрын
Awesome tutorial! Thanks!
@micycle8778
@micycle8778 5 жыл бұрын
When you get a programming ad on a yt channel that teaches you how to program for free
@numbertoast764
@numbertoast764 3 жыл бұрын
When you get your second like on a comment after 1 year
@dandapanidas351
@dandapanidas351 4 жыл бұрын
very nice video for socket programming in python
@salimsalim-wv1dm
@salimsalim-wv1dm 5 жыл бұрын
The best Channel From Morocco BigUp
@sentdex
@sentdex 5 жыл бұрын
Thanks!
@yassinemessaoudi
@yassinemessaoudi 5 жыл бұрын
Great tuto i really need that ! thank you !
@sentdex
@sentdex 5 жыл бұрын
Happy to make em!
@NamasivayamC
@NamasivayamC 4 жыл бұрын
Really appreciate your work and video
@RufusVidS
@RufusVidS 3 жыл бұрын
I think you should have pointed out the distinction that the first socket you create in the server (s) is not actually the socket that will be used for communication. It is the listening socket, which only gets connection requests. The clientsocket that is created is the actually communication socket and is actually on a different port. I think the early awareness in intro tutorials will help avoid confusion. Great tuts, btw!
@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".
@shwethamachani2093
@shwethamachani2093 5 жыл бұрын
Hi Harrison, Can I request you to make tutorial on networking and how Python widely used in networking? And...Thank you so much,you have no idea, how easily I had learnt Python by your tutorials.🙌😊
@danverzhao9912
@danverzhao9912 2 жыл бұрын
Incredible, this is very clear
@user-tl8ny2jk7h
@user-tl8ny2jk7h 3 жыл бұрын
this video was amazing! thank you
@jerylin1491
@jerylin1491 3 жыл бұрын
This is very helpful, huge thanks
@luccaviccini8787
@luccaviccini8787 5 жыл бұрын
Loved the video!!! Please do one for UDP connection!!
@alexchege2271
@alexchege2271 4 жыл бұрын
Excellent one. Love it
@mohammadespahrom3295
@mohammadespahrom3295 3 жыл бұрын
Excellent training video good job !!!!
@leomanangka1957
@leomanangka1957 4 жыл бұрын
This what i need for my robotic project, thanks
@equiposdecalor8077
@equiposdecalor8077 5 жыл бұрын
Thanks Bro your video helped me to finish my code
@tonycardinal413
@tonycardinal413 Жыл бұрын
Awesome video thanks! Question: does the socket named s in the server code refer to the same s in the client code? In other words is the "s" in both server.py and the "s" in client.py refer to the same socket (the socket on the server) Or do both S's refer to the socket on the client. Thanks. Maybe they are the same S since they are on the same machine??
@AbhishekKumar-mq1tt
@AbhishekKumar-mq1tt 5 жыл бұрын
Thank u for this awesome video
@robertmorrison1657
@robertmorrison1657 5 жыл бұрын
That is one funny cup you have.
@elachichai
@elachichai 3 жыл бұрын
Excellent. Please do demo of other Inter-Process communication techniques. XML-RPC, Event Driven systems, Message Queues, Callbacks, etc - in similar simple video and preferably Python.
@111ark
@111ark 4 жыл бұрын
Wow. 7:38 - you can do cmd on the address bar of the location ! Neat !
@shubhamgupta4237
@shubhamgupta4237 5 жыл бұрын
thank you sentdex for such an amazing video. I am a 15 years old boy who is really passionate about python. I am working on web development using Django and machine learning using tensorflow and scikit learn. I am largely dependent on your awesome videos to learn. can you please suggest something to me? By the way a heartfelt thank you...
@sentdex
@sentdex 5 жыл бұрын
Start trying to build things and work on your own projects.
@shubhamgupta4237
@shubhamgupta4237 5 жыл бұрын
@@sentdex i am working on a website and would like to show it you once i am done. How can i ????
@shubhamgupta4237
@shubhamgupta4237 5 жыл бұрын
@WALLSNAP exactly. can we talk some further as we both are beginners? my email id shubhastro2@gmail.com
@thorodinson7467
@thorodinson7467 5 жыл бұрын
ay teenager python gang
@kabirsingh4230
@kabirsingh4230 5 жыл бұрын
Become a Physicist learn the math behind machine learning first, then start using sci kit
@erfannariman
@erfannariman 5 жыл бұрын
A sentdex video? First liking, then watching
@OliverHext
@OliverHext 3 жыл бұрын
Nice video. Clearly explained
@muhammadomeraffan475
@muhammadomeraffan475 5 жыл бұрын
Sir I couldn't be more thankful for all your tutorials... I would also want to request a tutorial on seq2seq modeling on sequence data mapping onta sequence, in keras please...
@sentdex
@sentdex 5 жыл бұрын
Maybe in 2019. Not gonna touch tf til 2.0
@muhammadomeraffan475
@muhammadomeraffan475 5 жыл бұрын
The tf 2.0 Alpha is available though: www.tensorflow.org/community/roadmap But will be waiting for it. Thank you 🙂
@sentdex
@sentdex 5 жыл бұрын
Yeah, I'm aware, just not looking to put a bunch of time into covering an alpha and then it getting deprecated. 😵
@MasterChi__
@MasterChi__ 2 жыл бұрын
Awesome video! Kinda looks like snowden!
@Zephyr-tg9hu
@Zephyr-tg9hu 3 жыл бұрын
Everyone gansta 'til sentdex starts drinking out of a cheeseburger
@chief6685
@chief6685 4 жыл бұрын
Thanks for the sockets work describe
@mayanmaster92
@mayanmaster92 2 жыл бұрын
I'm glad he gets right into the code but I really need to know what this whole socket/server/client stuff is, what it's used for, etc... Does anyone have a video that explains all that?
Python Sockets Simply Explained
39:33
NeuralNine
Рет қаралды 159 М.
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 5 МЛН
GIANT umbrella by Tsuriki Show
00:15
Tsuriki Show
Рет қаралды 7 МЛН
Алексей Щербаков разнес ВДВшников
00:47
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 10 МЛН
15 Python Projects in Under 15 Minutes (Code Included)
12:37
Tech With Tim
Рет қаралды 2 МЛН
Pandas Dataframes on your GPU w/ CuDF
12:04
sentdex
Рет қаралды 42 М.
Websockets in Python
17:52
APMonitor.com
Рет қаралды 30 М.
ChatGPT API in Python
35:18
sentdex
Рет қаралды 179 М.
Stop, Intel’s Already Dead! - AMD Ryzen 9600X & 9700X Review
13:47
Linus Tech Tips
Рет қаралды 1,1 МЛН
ChatGLM: The ChatGPT killer? Checking out ChatGLM6B
16:37
sentdex
Рет қаралды 102 М.
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 5 МЛН