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

///Sockets Tutorial with Python 3 part 1 – sending and receiving data

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

FavoriteLoadingAdd to favorites

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:

Channel membership:
Discord:
Support the content:
Twitter:
Facebook:
Twitch:
G+:

#sockets #python #tutorial

source

By |2019-07-22T21:22:56+00:00July 22nd, 2019|Python Video Tutorials|34 Comments

34 Comments

  1. Daneil es July 22, 2019 at 9:22 pm - Reply

    Hey man , really good tutorial but since I'm a beginner i had a question where exactly should i put the ip address if I'm running this program on two separate devices?

  2. müptezel cihat July 22, 2019 at 9:22 pm - Reply

    1:00 because there is WAYY TOO MUCH SOCKET IN THIS CODE

  3. theAbhi- eYe July 22, 2019 at 9:22 pm - Reply

    socket.gethostbyname(""), FOR mac users

  4. Nikhil Kashyap July 22, 2019 at 9:22 pm - Reply

    why did u convert the message sent from clientsocket in bytes?

  5. Jack Luft July 22, 2019 at 9:22 pm - Reply

    U should have a video on how to connect to the internet from python

  6. P L July 22, 2019 at 9:22 pm - Reply

    thanks a lot,man!It is super helpful. You are really a life savior to me!

  7. Jushtan July 22, 2019 at 9:22 pm - Reply

    "We've got a lot of stuff to cover, so lets get into it." Here I thought I was watching sentdex, not Derek Banas

  8. Dean Lopez July 22, 2019 at 9:22 pm - Reply

    Your confusion at the 4:00 mark about clientsocket being the "foreign socket" is weird. Think of a socket as a pipe with two ends, one local on your machine and the other on the "foreign" machine. Data has to flow into the local end on your machine to get to the end on the foreign machine. So, there is no "foreign socket", there's just one socket with "foreign" and local ends. You're confusing your viewers by implying there's more than one socket. So ok, you might ask "Well what about socket s then?" Yes, socket s is still there, but it is the listen socket, and accept() creates a new, totally separate socket (that you happened to call clientsocket) for data transfer so that s can continue to listen for more connections. All your sends and receives occur on clientsocket. You could have simply called that socket "sendreceivesocket" to make it clearer what it's for.

  9. vivek singh July 22, 2019 at 9:22 pm - Reply

    Please make a video on socketio

  10. exposer July 22, 2019 at 9:22 pm - Reply

    But they both work on the machine locally

  11. exposer July 22, 2019 at 9:22 pm - Reply

    Guys my TCP are not connecting over public IP of the server what can I do

  12. Equipos De Calor July 22, 2019 at 9:22 pm - Reply

    Thanks Bro your video helped me to finish my code

  13. Iliyan Iliev July 22, 2019 at 9:22 pm - Reply

    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 <3

    Hint: You helped another youtuber with this in one of his streams. I think you both rock and maybe you should work together

  14. Bulbul Ahmed July 22, 2019 at 9:22 pm - Reply

    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.

  15. Angel Santander July 22, 2019 at 9:22 pm - Reply

    No puede pronunciar Miguel Hurtado 🤣🤣🤣, pretty funny attempt

  16. Sarthak Misraa July 22, 2019 at 9:22 pm - Reply

    In AF_INET

    AF stands for Address Family
    INET probably for internet as it too works on tcp

  17. Kikzzz July 22, 2019 at 9:22 pm - Reply

    That mug made my day!

  18. Eduard Guber July 22, 2019 at 9:22 pm - Reply

    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.

  19. Casowsky July 22, 2019 at 9:22 pm - Reply

    That Burger Mug tho

  20. Atul Joshi July 22, 2019 at 9:22 pm - Reply

    Yes from 4:15 I also feel the same that it should be so what like s.send or s.recv
    Anyone can explain the why it is not as it is

  21. Ofri Kirshen July 22, 2019 at 9:22 pm - Reply

    AF_INET and SOCK_STREAM are the defaults

  22. Shyam Kumar July 22, 2019 at 9:23 pm - Reply

    :New folderSocket>py client.py

    length is: b'25 '

    Traceback (most recent call last):

    File "client.py", line 18, in <module>

    full_msg+=msg.decode("utf-8")

    TypeError: can't concat str to bytes
    Iam unable to find error please help

  23. Shyam Kumar July 22, 2019 at 9:23 pm - Reply

    its was very useful ,thank you .When I tried to connect to server from client it was connected.when I disconnect system internet and connect again its rejecting connection with client and after restart the server code only its working how to write code without restarting server when IP changed

  24. Mew July 22, 2019 at 9:23 pm - Reply

    Hi sentdex! I'm just beginning with learning to program and I thought that making a chat program would be fun for a start. But I got a question, how does your Python 3.?.? look like that. I don't get the code to work in normal Python 3.7.3. Keep up your good videos!

  25. Fell0ut July 22, 2019 at 9:23 pm - Reply

    Sentdex, if it weren't for you and thenewboston, I would have probably quit programming a long time ago. Thank you for the videos man!

  26. Amit Maurya July 22, 2019 at 9:23 pm - Reply

    Hey Bro, you are my inspiration…..:-)

  27. BUBAI NAYAK July 22, 2019 at 9:23 pm - Reply

    if possible can ypo please make a video for Raspberrypi Bluetooth socket and quae communication

  28. CAMERAshow July 22, 2019 at 9:23 pm - Reply

    Hey Sentdex, u are cool. Could u make a deploy of that chat app u made in a internet host like heroku? It will close the series in a complete way. Thanx man keep going!!!!!

  29. Abhishek Singh July 22, 2019 at 9:23 pm - Reply

    hey, so i've been trying to follow along and i tried running the script on a vps but it didn't work, client side couldn't establish a connection. On local machine the scripts do work but after moving server.py to server it didn't.

  30. Jithu Nair July 22, 2019 at 9:23 pm - Reply

    Is this a complete or an ongoing series? Just wanna know before I start delving in it. Someone who's done with it, let me know please?

  31. Atomic Cubed July 22, 2019 at 9:23 pm - Reply

    Thank you for a great tutorial! A point to note is that F-string literals weren't introduced to Python until version 3.6, so not every version of Python3 will work.. Running this code in 3.5 or earlier will result in syntax errors for the print statement.

  32. Robert Kraciuk July 22, 2019 at 9:23 pm - Reply

    right on time my man, just when i started looking for sockets tutorials right on goddamn time, love it !

  33. SAVAS July 22, 2019 at 9:23 pm - Reply

    hello , I want sending image and video but I dont know 🙂 please help me

  34. jack captain July 22, 2019 at 9:23 pm - Reply

    can you make a video which cover following programs using client-server test kit.
    1. the client program should be able to vary the number of messages sent and their size; the server should detect when a message from a particular client is missed.
    2. make a client program that repeatedly reads a line of input from the user, sends it to the server in a UDP datagram message, then receives a message from the server. The client sets a timeout on its socket so that it can inform the user when the server does not reply. Test this client program with the server program
    3. the client repeatedly takes a line of user’s input and writes it to the stream and the server reads repeatedly from the stream, printing out the result of each read. Make a comparison between sending data in UDP datagram messages and over a stream.
    4. write a program to test the effect on the sender when the receiver crashes, and vice-versa.

Leave A Comment

*