Тёмный

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

sentdex
Подписаться 1,3 млн
Просмотров 799 тыс.
50% 1

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

Опубликовано:

 

10 мар 2019

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 628   
@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
@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
@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.
@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.
@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!
@1944GPW
@1944GPW 4 года назад
Full marks to you for using a nice big font to make the code clearly easy to read on RU-vid. 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.
@RyuWeiWei
@RyuWeiWei 4 года назад
A class and practice of 2 hrs. Explained within 15min with making so much sense. I like it.
@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 2 года назад
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
@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!
@oliverli9630
@oliverli9630 4 года назад
while i was looking for socket tutorials, there it is! lovely! added to favorite for later use. really useful in trading.
@robertkraciuk2753
@robertkraciuk2753 5 лет назад
right on time my man, just when i started looking for sockets tutorials right on goddamn time, love it !
@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
@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!!
@pythonbibye
@pythonbibye 3 года назад
This was so absolutely helpful!! Thank you so much and keep up with the good work!! I really love your tutorials
@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!!!
@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😍
@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!
@izaquemiguelgabriel
@izaquemiguelgabriel 4 года назад
That’s exactly what I was looking for! Thanks, sir!
@lightEuphoria
@lightEuphoria 11 месяцев назад
One of the best tutorials on Yotube. Thank you so much for such a great and enthusiastic explanation! It all finally works
@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.
@SmashPhysical
@SmashPhysical 3 года назад
Was looking for something straightforward on this topic, thanks!
@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!
@raiyanyahya
@raiyanyahya 5 лет назад
Great video Sentdex .. thank you for the effort !!
@hamadaag5659
@hamadaag5659 4 года назад
“And then an exclamation mark because this is serious business” I laughed my pants off hearing that😂
@Kefford666
@Kefford666 3 года назад
Man your videos are so helpful, and Python is just too fun! ❤️
@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
@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 ❤️
@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! :)
@pafnutiytheartist
@pafnutiytheartist 5 лет назад
Thank you for this tutorial, i tried to use sockets in python a while back and got quite confused at first.
@garcand
@garcand 3 года назад
Thank you for helping me with my first python project. Creating a socket :)
@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
@Lucifer-wd7gh
@Lucifer-wd7gh 3 года назад
I love how he smile everytime 😀 👍
@pl1365
@pl1365 4 года назад
thanks a lot,man!It is super helpful. You are really a life savior to me!
@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
@ahmdzamir8218
@ahmdzamir8218 2 года назад
Thankyou so much for this tutorial!
@danz5476
@danz5476 2 года назад
THE BEST cup I saw in my life !
@longphamthanh2010
@longphamthanh2010 Год назад
Short and very impact video, really good for beginner like me.
@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.
@suprecam9880
@suprecam9880 3 года назад
bro thank you for the tutorials. helping me out a lot putting this all into regular people speak lol
@paulcopeland4446
@paulcopeland4446 3 года назад
Oh man, perfect explainer. Thanks!
@nestorbongiorno1342
@nestorbongiorno1342 3 года назад
Excellent explanation! Thank you!
@JohnBrian-zs5yp
@JohnBrian-zs5yp Год назад
Amazing tutorial, thanks 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.
@seanshimon
@seanshimon Месяц назад
`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.
@sistematico17
@sistematico17 2 года назад
you are an amazing educator! thank you
@swiftlyexplained703
@swiftlyexplained703 3 года назад
Awesome tutorial! Thanks!
@sudeep.g
@sudeep.g 5 лет назад
Love it! Exactly what I needed
@sentdex
@sentdex 5 лет назад
Great!
@anigraytion7987
@anigraytion7987 3 года назад
So is this: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-doEqUhFiQS4.html
@NamasivayamC
@NamasivayamC 4 года назад
Really appreciate your work and video
@ShalabhBhatnagar-vn4he
@ShalabhBhatnagar-vn4he 4 года назад
Master class by the masterclass! Thanks!
@user-tl8ny2jk7h
@user-tl8ny2jk7h 3 года назад
this video was amazing! thank you
@emilypark8144
@emilypark8144 4 года назад
thank you sooooooo much!! you are the best Python teacher :)
@jerylin1491
@jerylin1491 3 года назад
This is very helpful, huge thanks
@JoshxDude92
@JoshxDude92 3 года назад
Dude, super helpful. Thanks!
@megha7243
@megha7243 3 года назад
wow! that was interesting. Thank you
@leomanangka1957
@leomanangka1957 4 года назад
This what i need for my robotic project, thanks
@danverzhao9912
@danverzhao9912 2 года назад
Incredible, this is very clear
@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.
@coddr4778
@coddr4778 3 года назад
Are you an god??? you can prgramming really gooood , dont stop with this :)
@man.h
@man.h 5 лет назад
Thank you soooooo much.! All best from Germany
@sentdex
@sentdex 5 лет назад
You're welcome!
@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.
@user-cc8kb
@user-cc8kb 2 года назад
cool tutorial! thank you very much :)
@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
@mohammadespahrom3295
@mohammadespahrom3295 3 года назад
Excellent training video good job !!!!
@AbhishekKumar-mq1tt
@AbhishekKumar-mq1tt 5 лет назад
Thank u for this awesome video
@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".
@alexchege2271
@alexchege2271 4 года назад
Excellent one. Love it
@academicpreparation8497
@academicpreparation8497 5 лет назад
Hey Bro, you are my inspiration.....:-)
@yassinemessaoudi
@yassinemessaoudi 5 лет назад
Great tuto i really need that ! thank you !
@sentdex
@sentdex 5 лет назад
Happy to make em!
@equiposdecalor8077
@equiposdecalor8077 4 года назад
Thanks Bro your video helped me to finish my code
@gregoryfenn1462
@gregoryfenn1462 3 года назад
999k subs, you’re sooo close!
@111ark
@111ark 4 года назад
Wow. 7:38 - you can do cmd on the address bar of the location ! Neat !
@PascalThalmann
@PascalThalmann 4 года назад
Excellent explanation. Thx
@OliverHext
@OliverHext 3 года назад
Nice video. Clearly explained
@dandapanidas351
@dandapanidas351 4 года назад
very nice video for socket programming in python
@paul100plus2
@paul100plus2 4 года назад
Very nice Video, it is a good tutorial!!! PS: I am sorry about mistakes in this text, I am from Germany.
@SoumilShah
@SoumilShah 5 лет назад
finally tutorial i wanted great
@anigraytion7987
@anigraytion7987 3 года назад
Here is another tutorial from him i recommend then: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-doEqUhFiQS4.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?
@JorgeMartinez-zg1wj
@JorgeMartinez-zg1wj 4 года назад
I don't understand how your code ever gets to if len(msg)
@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
@carlosedubarreto
@carlosedubarreto 3 года назад
Amazing explanations!!!!!
@shwethamachani2093
@shwethamachani2093 4 года назад
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.🙌😊
@chief6685
@chief6685 3 года назад
Thanks for the sockets work describe
@salimsalim-wv1dm
@salimsalim-wv1dm 5 лет назад
The best Channel From Morocco BigUp
@sentdex
@sentdex 5 лет назад
Thanks!
@azzakialjaylani7679
@azzakialjaylani7679 4 года назад
I am new subscriber, but i found your lessons very useful. Thank you.
@anigraytion7987
@anigraytion7987 3 года назад
Here is another one i recommend: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-doEqUhFiQS4.html
@MrFlipflops4
@MrFlipflops4 3 года назад
This guy is the man!!
@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??
@benjaminbenjamin8834
@benjaminbenjamin8834 2 года назад
Amazing...........This guy is AWESOME!
@marcelolopesdeamorimjunior9723
@marcelolopesdeamorimjunior9723 3 года назад
Yesir! Great material
@luccaviccini8787
@luccaviccini8787 5 лет назад
Loved the video!!! Please do one for UDP connection!!
@micycle8778
@micycle8778 5 лет назад
6:00 I have that mug. Got it half off from a going out of business sale.
@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!
@erfannariman
@erfannariman 5 лет назад
A sentdex video? First liking, then watching
@chesster5981
@chesster5981 Год назад
1:18 AF_INET is an address family that is used to designate the type of addresses that your socket can communicate with (in this case, Internet Protocol v4 addresses). When you create a socket, you have to specify its address family, and then you can only use addresses of that type with the socket. The Linux kernel, for example, supports 29 other address families such as UNIX (AF_UNIX) sockets and IPX (AF_IPX), and also communications with IRDA and Bluetooth (AF_IRDA and AF_BLUETOOTH, but it is doubtful you'll use these at such a low level). For the most part, sticking with AF_INET for socket programming over a network is the safest option. There is also AF_INET6 for Internet Protocol v6 addresses. Hope this helps, Share Improve this answer Follow edited Nov 17, 2021 at 0:02 Gabriel Staples's user avatar Gabriel Staples 27.5k99 gold badges149149 silver badges202202 bronze badges answered Oct 20, 2009 at 11:46 George Shore's user avatar George Shore
@user-ln2qr5mn8r
@user-ln2qr5mn8r 5 лет назад
That mug made my day!
@anigraytion7987
@anigraytion7987 3 года назад
So will this: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-doEqUhFiQS4.html
@windyruss
@windyruss 3 года назад
awesome mug!
Далее
Modern Python logging
21:32
Просмотров 147 тыс.
15 Python Libraries You Should Know About
14:54
Просмотров 356 тыс.
5 Useful F-String Tricks In Python
10:02
Просмотров 247 тыс.
Top 18 Most Useful Python Modules
10:50
Просмотров 922 тыс.
Better Attention is All You Need
14:29
Просмотров 62 тыс.
Letting GPT-4 Control My Terminal (TermGPT)
23:12
Просмотров 74 тыс.
ChatGPT API in Python
35:18
Просмотров 176 тыс.