Navigate Select ESC Close

File Transfer via Sockets in Python

2022-09-12 Science & Technology
72.7k
2.1k
106
NeuralNine
NeuralNine
470.0k subscribers

Unlock all features

FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.

Description

In this video, we learn how to transfer files via sockets in Python. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm 🎵 Outro Music From: https://www.bensound.com/

Top Comments (10)

@missipgaming6174 2022-09-13

You are by far my favorite source for Python lessons. 1. You have a solid intro. 2. Your videos are not too long. 3. Even though the videos are not that long, you are clear on your explanation. Thank you for doing this.

40
@lastdanceLL 2022-12-19

I'm seeing verbatim copies of this code being used all over the place and it has to stop. This code is filled with unreliable constructs. It exhibits every python sockets' bad practice I've seen in the last 10+ years. 1) If you don't check the return value from send() that's a bug. You should be using sendall() for all the sends that you're not checking the return value of, which in this case is all of them. 2) Although perhaps not a big deal for this particular example, assuming that a fixed chunk of bytes like 1024 will end on a utf-8-encoded unicode character boundary is incorrect; 3) The biggest mistake is your assumption the every single send() or sendall() will be read by a single recv on the server side. That's not how tcp works and not how python SOCK_STREAM sockets work. If you send 1022 bytes in one send and 25 bytes in the next send, then on the server side you may receive 50 bytes in your first recv(1024) and then 100 bytes on you next recv(1024). Or you might receive 1024 bytes in your first recv(1024) but then only 1 byte in your next recv(1024). In your case, you might receive the file name, the file size, and a big chunk of the file itself in your first recv(1024) that you're assigning to the variable file_name. See the following answer on stack overflow for more details: https://stackoverflow.com/questions/43420075/python-socket-not-receiving-without-sending/43420503#43420503.

24 2 replies
@adventinfomax6903 2022-09-14

You've actually got so quality stuff on your channel. Keep that up man!

3
@davidtindell950 2023-12-22

Thank you! I do like your inclusion of the progress bar!!

1
@minhajhossain337 2023-03-03

I love your videos Florian. Because, you always explain everything very easily in a short time period 😊😊😊

1
@yunisguliyev3815 2024-02-28

i am 70% sure that he recorded this video after break up. got the vibes

1
@felloforest 2023-02-17

very informative. Not too brief but you get the concepts behind it.

0
@ethanberg1 2024-03-09

Thank you! You just made my life easier next week!

0
@tommyhuffman7499 2023-08-04

Your channel is underrated

0
@businessdissection130 2022-09-12

Honestly, I started watching your videos for the intro music. And stayed for the content.

0

Unlock the Data Inside
Turn Videos into Knowledge

  • Get FREE 10/day: transcripts, summaries, chats
  • Chat with videos, export text & PDF
  • $1 free API credit for RAG, chatbots & research

Free forever plan • All features unlocked

App screenshot