Sockets Tutorial with Python 3 part 2 – buffering and streaming data

Welcome to part 2 of the sockets tutorial with Python. In the previous tutorial, we learned how we could send and receive data using sockets, but then we illustrated the problem that can arise when our communication exceeds our buffer size. In this tutorial, we’ll talk about overcoming this!

Source code and text-based tutorial:

Channel membership:
Support the content:

#socket #networking #python


  1. Hans Müller on

    Hi sentdex, definitely love your videos! Some time ago, I stumpled upon a problem in python. I’m kind of a beginner in python 🙂 As you might know, the UDP and TCP max buffer size is about 64kilobytes. I wanted to stream video via some kind of networking socket to a c# application but the array of one opencv camera frame was about 9,5Mb! I read something about compression with ffmpeg and then sending it but I did’nt get it to run and since you really know a lot about python I was wondering if you could do a short video that deals with this topic in this series since it’s pretty fitting…. Thanks for you TF vids btw, would love to see a series with TF 2.0!

  2. Sh Mj on

    Can u please do a series of Algorithms ? Like A-Star or sieve of Eratosthenes I mean the most widely used simple algorithms it would be of great help 😅

  3. Ben Myers123 on

    Hi sentdex,
    If it’s relevant, are you able to show us how you might communicate with say a printer using sockets? Thanks for reading.

  4. Richard Aspden on

    Thanks for explaining the msg = f'{len(msg):{HEADERSIZE}}’ thing, starting at 7:08 since I was wondering what that all meant and I didn’t know what to google to look it up. 🙂

  5. pafnutiytheartist on

    Since you have to convert you message to byte array before sending, why not send length header in binary(uint32 for example) instead of decimal string?

  6. Capt. Alhadinon on

    Hi sentdex,
    Nice tutorial!
    There is one thing many coders on youtube do not get. And this is efficient coding. I do not know in which order you prepare your videos (text before video, or the other way round), but in some cases your code lacks a bit of perfection. For example, as you were printing the length of the message, and then converting it right after it again, with a little help of copy and paste.
    Imho we all want to be good coders at least, but being efficient coders should be the desired goal in the end. 😊
    Don’t get me wrong sentdex, I really love watching your tutorials, because they help me getting a better Python coder. And I am on the way of perfecting it day by day.
    Anyways, keep on going, you’re awesome! 😁

  7. Speak To The Point on

    Really Good. Sentdex was the inspiration for me to learn Python. Thanks for keeping me on the edge always.

  8. Mohit Udupa on

    I find it easier to work with bash on windows for socket programming. You don’t get that socket is already being used error on bash.

  9. Knight Rider on

    Can someone please help me to understand what print(f'{len(msg):<20}'+msg) does its showing syntax error for me please help, any kind of help will be appreciated

  10. Sébastien Lavoie on

    Thank you sentdex, you are a very inspiring teacher. Your enthusiasm is always contagious! See you soon as a $upporter ;).


Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons