Python Socket Programming Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 เม.ย. 2020
  • This socket programming tutorial will show you how to connect multiple clients to a server using python 3 sockets. It covers how to send messages from clients to server and from server to clients. I will also show you how to host your socket server locally or globally across the internet so anyone can connect. This uses the python 3 socket and threading module.
    Code Download: techwithtim.net/tutorials/soc...
    ◾◾◾◾◾
    💻 Enroll in The Fundamentals of Programming w/ Python
    tech-with-tim.teachable.com/p...
    📸 Instagram: / tech_with_tim
    🌎 Website techwithtim.net
    📱 Twitter: / techwithtimm
    ⭐ Discord: / discord
    📝 LinkedIn: / tim-ruscica-82631b179
    📂 GitHub: github.com/techwithtim
    🔊 Podcast: anchor.fm/tech-with-tim
    💵 One-Time Donations: www.paypal.com/donate/?token=...
    💰 Patreon: / techwithtim
    ◾◾◾◾◾◾
    ⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡
    ⭐ Tags ⭐
    - Tech With Tim
    - Python Tutorials
    - Python Socket Programming
    - Socket Programming Python
    - Python Sockets Multiple Clients
    - Socket Tutorial Python
    - Python 3 Sockets
    ⭐ Hashtags ⭐
    #python #sockets

ความคิดเห็น • 1K

  • @SThomas1972
    @SThomas1972 4 ปีที่แล้ว +698

    Hi nice bit of coding but there is a number of errors in your networking description. Firstly the modem is not where your public address will sit it will be on the wan interface of the router and the router is in fact firewall as it will hide the private addresses behind the public address.
    You are dealing with tcp ports the is 65535 ports full list en.m.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
    And the number you are seeing with the received message on the server is in fact the source port.
    Also you would not run your server on the modem it would be run inside your net work and using Nat you would forward connections to the server via the router but this would be bad idea on a home internet connection as the router will not be secure enough as you normally what to this via a DMZ.

    • @TechWithTim
      @TechWithTim  4 ปีที่แล้ว +283

      Thank you! Ya I’m no networking pro clearly. Hopefully that explanation at least have a general concept of a private network. Thanks for the comment :)

    • @SThomas1972
      @SThomas1972 4 ปีที่แล้ว +183

      Tech With Tim I am a network security engineer so that is my bread and butter. I work with Nat and firewalls everyday. But happy to help you.

    • @younlok1081
      @younlok1081 4 ปีที่แล้ว +11

      @@SThomas1972 i was planning to put a small server just to chat with my friends
      in my home internet so this is not safe ??
      should i cancel the idea ??
      i was going just sto specify a port in the router to get to my port
      is that not safe ??

    • @younlok1081
      @younlok1081 4 ปีที่แล้ว +3

      @@SThomas1972 also even if it just http requests ??

    • @000sakis
      @000sakis 4 ปีที่แล้ว +1

      I'm a bit confused .. when I use my public IP it says there's no such IP... I tried port forwarding my pcs IP, will that work?

  • @ericbeard7007
    @ericbeard7007 4 ปีที่แล้ว +373

    Been eating up the python content lately, finally a guy with a decent Mike and understandable explanations

    • @ecniv5991
      @ecniv5991 3 ปีที่แล้ว +70

      Mike

    • @push2talk95
      @push2talk95 3 ปีที่แล้ว +44

      Mike

    • @ericbeard7007
      @ericbeard7007 3 ปีที่แล้ว +40

      Yeah Mikerafone. You know that thing that you speak into and it amplifies sound waves. Or the mic that autotext changes to Mike. Either or . .

    • @chersymale
      @chersymale 3 ปีที่แล้ว +4

      @@ericbeard7007 Mike

    • @ericbeard7007
      @ericbeard7007 3 ปีที่แล้ว +6

      I was not eing serious for people who replied

  • @kellyw7545
    @kellyw7545 2 ปีที่แล้ว +3

    Spent the last two weeks trying to understand why my simple server - client simulation was not working ; I cannot count how many tutorials and searches I have waded through - wish I found you sooner - I am definately sharing your channel. Not only did you fill in some seemingly simple blanks your explanations of everything were thorough and clear and showing your process all the way through. There are so many ways to trip up if you are new to working with sockets and your video prevents just about all of them. Thank You!!

  • @CrashingThunder
    @CrashingThunder 4 ปีที่แล้ว +17

    Thanks for this video! You always are able to explain things really thoroughly and succinctly. I've been working on my web related Python skills, so this was a good overview of something I needed to learn.

  • @Shadow-oy3ut
    @Shadow-oy3ut 3 ปีที่แล้ว +5

    Thank you Tim!!! I have been watching all your videos since 4 months ago, i love them all because you explain everything so good. I was so close ending my coding career, but you helped me up from being stuck on worthless beginner videos. And because of this video, i subscribe, like and share this video. I almost never do this on youtube, again, a HUGE THANKS!!!❤❤

  • @Koubles
    @Koubles 6 หลายเดือนก่อน +4

    Despite the errors, this video is incredibly useful for getting a head-start on getting a python server running. My degree courses never really taught me python let alone sockets, so this has been a MASSIVE help getting me going with a python server I need to have interacting with a MySQL database for my senior project.

  • @matiasalloatti3509
    @matiasalloatti3509 4 ปีที่แล้ว +7

    Thank you for this incredible content! I started working on an online ccg game with what you showed in the online python multiplayer game. This tutorial make it much clear how the connection worked. Thank you again for the tutorials and keep it up with the good work!!! Best to you from Argentina!

  • @francisparent-valiquette4113
    @francisparent-valiquette4113 ปีที่แล้ว +2

    Hey Tim!
    Just found your channel today, I was looking to implement websocket to run distant function and I have to admit I'm impress by how you manage to give enough informations so we can get started quickly without falling in the "too much informations trap". You're an inspiration for me!
    Thanks this tutorial is what I was looking for!

  • @athatien8303
    @athatien8303 2 ปีที่แล้ว +1

    I really like the way you taught. You always start with the big picture so everybody can get a basic understanding about the topic then go to the minor details. Not to mention that your explanation is so intuitive and simple that I think even an 8 year-old kid could understand. Keep up with the good work

  • @link9645
    @link9645 4 ปีที่แล้ว +7

    Great tutorial. Recently learned how to deal with multi threading and created a chat app, and I can say socket programming is really cool.

  • @drluswala
    @drluswala 4 ปีที่แล้ว +254

    I am still a beginner in Python but this was really easy to understand. Thank you Tim!

    • @dnetne5508
      @dnetne5508 4 ปีที่แล้ว +8

      same - I also got to know threading on the way :'D

    • @CSSuccessGamer
      @CSSuccessGamer 4 ปีที่แล้ว +20

      im also a beginner and have no clue whats going on

    • @aliffnabil5542
      @aliffnabil5542 4 ปีที่แล้ว +5

      @@CSSuccessGamer same here bro i just copied the code he did without knowing what's really going on

    • @universenerdd
      @universenerdd 3 ปีที่แล้ว +4

      python is a great first language, and once you learn python it is quite easy to understand others, which have an even greater flexibility than python

    • @universenerdd
      @universenerdd 3 ปีที่แล้ว +6

      @@aliffnabil5542 don't be a script kiddie!

  • @johngarcia625
    @johngarcia625 3 ปีที่แล้ว

    Tim, thank for the video and great explanations. I recently was on my second interview with a FAANG company, and even though I am not a programmer and stated such as I was considered for communications position. I was knocked out of the running from the position as I did not know how to open a socket (on a satellite, lol! Will not be done unless they are the owner or operator.) using python. So I search the Internet for the solution. I found that your video and explanations were what I needed. Thanks for your tutorial, I can now answer a questions about opening up a socket using python!

  • @TranquilKr
    @TranquilKr ปีที่แล้ว +2

    This is such an amazing tutorial. I will read up on the technical details myself, but the programming part was on point. Thanks a lot for the efforts put into making this video, Tim!

  • @TechWithTim
    @TechWithTim  4 ปีที่แล้ว +104

    What you guys think of that intro ;) And code is available here: techwithtim.net/tutorials/socket-programming/ . Also kindly note that there are some errors in this video, I've pinned a comment that points out some of the major ones. Sorry guys, I'm learning too and will try my best to avoid such issues in future videos!

    • @Joshua-dl3ns
      @Joshua-dl3ns 4 ปีที่แล้ว

      awesome! :)

    • @rafasantos23
      @rafasantos23 4 ปีที่แล้ว

      Great

    • @michaeldamolsen
      @michaeldamolsen 4 ปีที่แล้ว +2

      You didn't do a terrible job at the networking primer. I would have done some of it differently, but I am an expert in the field :p The python part was excellent, clearly you are an expert in that field :) :)
      One thing to note on the ipconfig output: While your IPv4 address is private LAN local (RFC1918 addresses are not routed on the internet), your IPv6 prefix is publicly routed. 2607:fea8:: is allocated to Rogers Communications, and they sub-allocate to their customers, apparently as the "standard" /64 which is so handy for SLAAC.
      Thanks for all these excellent python videos, yours are several notches above most of what is available on youtube!

    • @TechWithTim
      @TechWithTim  4 ปีที่แล้ว +6

      @@michaeldamolsen Appreciate that Micheal!

    • @markogartnar5658
      @markogartnar5658 4 ปีที่แล้ว

      Amazing!

  • @angelpico3236
    @angelpico3236 4 ปีที่แล้ว +9

    This was a really good video Tim, look forward to part 2 !

  • @jeffdanks6920
    @jeffdanks6920 3 ปีที่แล้ว

    You are a life saver. I have been trying to study it for the past 3days and boom here you are

  • @shreyash462
    @shreyash462 2 ปีที่แล้ว +1

    The flow of your program and explanation was SPOT ON ! Just Awesome !

  • @abimbolaobadare6691
    @abimbolaobadare6691 4 ปีที่แล้ว +18

    love the new intro tim. Boss mode activated

  • @JLSXMK8
    @JLSXMK8 2 ปีที่แล้ว +29

    31:06 [WARNING]: For those of you on Windows, if you get an error saying "An operation was attempted on something that is not a socket", then make sure your "conn.close()" operation is not occurring within the "while(connected):" loop.

    • @mefredjikram9567
      @mefredjikram9567 2 ปีที่แล้ว

      yes i have a problem with conn.close() and am not good on python would you please tell me what shall i do?

    • @jeffreydoty8710
      @jeffreydoty8710 ปีที่แล้ว

      Lol I was trying to find it, thank you for the 'WARNING' was trying to find it but couldn't figure it out.
      Just curious, how did you know?

  • @akanobody5622
    @akanobody5622 2 ปีที่แล้ว +2

    Good tutorial, you are right (depend on the configuration you have) you can have a public ip in the company modem and a private ip in your local router router, that is a double NAT, it have pros and cons as all configurations. You can use TCP, UDP and others protocols depending on the layer. etc. Thanks for the tutorial.

  • @Clarin3t1
    @Clarin3t1 8 หลายเดือนก่อน

    Okay I'm a CS major taking Net computing and you are a better teacher than my teacher. Thank you for saving my life!

  • @rtkevans
    @rtkevans 2 ปีที่แล้ว +4

    Awesome video. A little late to the party here. At 28:00, HEADER = 64 bytes means the header can take up to 64 digits as chars in a string (1 byte / char). That means your header + payload string altogether can have a maximum character length of 9999999999999999999999999999999999999999999999999999999999999999.

  • @kvetoslavlizlorech63
    @kvetoslavlizlorech63 3 ปีที่แล้ว +172

    When ur coding socket belike : socket = socket.socket(socket.socket(),socket.socket.socket)
    Edit = 69 likes 😈

    • @DylanPiper
      @DylanPiper 3 ปีที่แล้ว +4

      hahah

    • @mews75
      @mews75 3 ปีที่แล้ว +5

      socket?

    • @ahmedthegreat3973
      @ahmedthegreat3973 3 ปีที่แล้ว +3

      LOL

    • @mert3976
      @mert3976 3 ปีที่แล้ว +2

      lol so true

    • @gavinthecrafter
      @gavinthecrafter 3 ปีที่แล้ว +8

      socket = {"socket": socket.socket(socket.socket(),socket.socket.socket), "socket": "socket"}
      socket.socket.socket(socket, "socket")

  • @MohammadYs77
    @MohammadYs77 2 หลายเดือนก่อน

    The best and most comprehensive socket programming (for beginners of course) tutorial I've ever seen. Thanks to you, I understood socket programming after 6 years🧡🧡🧡🧡

  • @Miriam-dk7nm
    @Miriam-dk7nm 4 ปีที่แล้ว

    Yesterday I though about a new programming project and I came to the conclusion that learning something about sockets would be a good idea. I guess I am going to start today, thank you ;)

  • @lingesann9098
    @lingesann9098 4 ปีที่แล้ว +7

    Hey buddy I am really big fan of yours you are really a great teacher I've learned a lot from this channel. Thanks man keep rocking from India🙏🙏🙏

  • @HIMixoid
    @HIMixoid 4 ปีที่แล้ว +4

    Oh gosh! This is super clear!
    Thank you for this tutorial! *THUMBS UP*

  • @erik-martin
    @erik-martin 3 ปีที่แล้ว +2

    @Tech With Tim Was cool watching this. I taught this to myself 7ish years ago and built a little client server chat app (a bit more functionality than this) overnight. Still one of my favorite projects (haven't done much coding in the last 7 years). It was pretty cool seeing this all summarized in under an hour, might jave to do some more fiddling with sockets. Also assume you are a fellow Canadian since you are on the Roger's network.

  • @ecvsio
    @ecvsio 2 ปีที่แล้ว

    Holy shit thanks man, I really appreciate how you explain everything thoroughly.
    like some people would skip the networking parts and assume most people who want to write a socket program know this.
    Really well done being thorough and not skipping anything just in case someone has some information gaps.
    thanks!

  • @duckslayr
    @duckslayr 4 ปีที่แล้ว +178

    Since you didn't know: 8 bytes can be a number up to 18 quintillion, or 18 with 18 zeros, which, when used as a header could represent a 18,000 Petabyte message. So a 64 Byte header is a bit overkill since it's 18 quintillion to the eighth power (6 x 10^57).

    • @TechWithTim
      @TechWithTim  4 ปีที่แล้ว +52

      LOL ya I should have known that 😅 maybe a header of 16 bytes would have been a better choice

    • @dnetne5508
      @dnetne5508 4 ปีที่แล้ว +5

      @@TechWithTim hahahahahahaha :'D

    • @RecursiveTriforce
      @RecursiveTriforce 4 ปีที่แล้ว +44

      Good argument. Bad numbers.
      1 Byte has 256 combinations.
      64 Bytes would be 256^(64) = 1.3E+154 combinations.
      So lengths from 0 to 2^512-1 are possible.
      Fun fact: 10^80 is a common estimate for the number of atoms in the observable universe.
      Our number (~10^154) is almost that number squared.
      So you could note a bit for every atom, take those bits and write those bits into every atom. Now use the string of bits you get from reading all the bits you wrote in this process and you are still nowhere near the maximum length.

    • @duckslayr
      @duckslayr 4 ปีที่แล้ว +5

      @@RecursiveTriforce Yeah, it was really rough math while I was tired and not thinking too straight. I was thinking it was near the atoms in the universe size though.

    •  4 ปีที่แล้ว +12

      @@duckslayr And now let's fix the math once again. He is talking about bytes, that he reserves 64 bytes as header, but he isn't using the whole length. He takes the length of the message as a number, converts it to string and then encodes it to the header. That means the maximum number for length is 10^64 - 1. It's actually one of the most inefficient methods I've ever seen.
      The crash that occurred when he was testing the client the first time wasn't that there is "some empty message" that is sent after connection but the client ended the connection immediately after establishing connection.
      I would suggest a little bit more research on the topic and it would be good to go.

  • @0x544D
    @0x544D 4 ปีที่แล้ว +8

    Thank you Tim ,
    i will just add some infos about making a public socket over the internet :
    - on the server side , you will have to add a new rule of type port being used to control connections for TCP / UDP .. mostly u will be using "tcp" in both the outbound and inbound rules.
    - probably run the scrip as admin just to avoid possible "Permission problems"
    - on the Client side u just gotta whitelist the client side program/app/script to allow all sending data over a tcp port .. else just go and add a rule as an inbound rule .
    - be carefull , hackers might actually exploit that to access your private stuff / mess the server , so unless you know what your doing .. practice just with trusted friends or alone .
    - do not forget setting up port-forwarding on the router , so instead having clients reaching that port exmpl "1337" on the modem public address , they will be redirected to local_ip:1337 instead of public_ip:1337, hopefully u get that.
    - I would suggest using NO-IP (ddns aka "Dynamic domain name server") instead of hardcoding you public ip directly .
    finally ,
    feel free to subscribe I'm making such vids maybe not as good as Tim's but we're getting there.

    • @aakashkukal
      @aakashkukal 3 ปีที่แล้ว +1

      Great, now tell me how can i do this stuff

  • @kalo5133
    @kalo5133 3 ปีที่แล้ว +1

    Intrinsically, i am very impressed by your work. Not to mention that, you always consider us as you and or come out with frequent encounter issues like setup, or common technical issues with clear explanation. Glad to have you as my coach toward my programming journey, appreciate your work!!

  • @Max-oj9tp
    @Max-oj9tp 4 ปีที่แล้ว

    Covers perfectly the basics of sockets, good job!

  • @baumths
    @baumths 4 ปีที่แล้ว +17

    Hey Tim! What about a series where you set up a server and client for like a chat or even a little game? A live stream day perhaps? Great content, keep it up!

    • @dominictarro4177
      @dominictarro4177 3 ปีที่แล้ว

      Been done on one of his 12 hour code sprints

  • @Joshua-dl3ns
    @Joshua-dl3ns 4 ปีที่แล้ว +89

    thats a really nice intro!

    • @zakariaabdisalam1728
      @zakariaabdisalam1728 4 ปีที่แล้ว +1

      wow i love that intro

    • @azidsecurity2536
      @azidsecurity2536 4 ปีที่แล้ว +3

      I got a netflix ad in the beginning of the video when I saw this comment and got really confused

    • @devnull0368
      @devnull0368 3 ปีที่แล้ว +1

      :eyes:

  • @parthkabra4968
    @parthkabra4968 3 ปีที่แล้ว

    I got inspiration from your chatting website. I even made frontend of it, and i am learning backend from you.. Thanks for everything

  • @tejasmandre666
    @tejasmandre666 4 ปีที่แล้ว +1

    Thanks man ! I was really trying hard to make threading in sockets, this resolved all of my queries

  • @TomerCnaan
    @TomerCnaan 4 ปีที่แล้ว +5

    Using select is a good choice for asynchronous servers.

  • @piyushlakhani3571
    @piyushlakhani3571 4 ปีที่แล้ว +3

    Great Job Tim!!! ,
    Love from Concordia University Library , Montreal

  • @copdatchoppa
    @copdatchoppa 2 ปีที่แล้ว

    I love this guy. He explains well and makes things not complicated. As a beginner, I'm glad that his explanations and demonstrations are clear, and I actually know what the hell is going on. Thank you

  • @Stevesteacher
    @Stevesteacher 3 ปีที่แล้ว

    Thank you! I've been struggling with this topic for a long time and you helped me understand every bit of it :)

  • @mk677hd
    @mk677hd 4 ปีที่แล้ว +4

    SOCK_STREAM is for TCP - which is the transport protocol widely used, not some vague thing meaning "streaming data"
    Other options include ones for UDP

  • @jyvben1520
    @jyvben1520 4 ปีที่แล้ว +4

    10;45 start of programming explanation, first part was networking lan/wan info,
    no need to change the firewall on the client computers !
    you might need to open a port range on your router and redirect that to your server and then change the firewall rules on your server to accept requests coming from your router.

  • @pi_r_mlm
    @pi_r_mlm 4 ปีที่แล้ว +1

    Wow ! I love this video !
    A new way to speak quietly in class

  • @shreypatel9051
    @shreypatel9051 4 ปีที่แล้ว +1

    The python sockets tutorial i never had and always needed. Thank You

  • @bauerfischer3030
    @bauerfischer3030 3 ปีที่แล้ว +9

    The SOCK_STREAM means connection oriented TCP protocol, for all that wondered :D ( 17:53 )

  • @everton.colombo
    @everton.colombo 4 ปีที่แล้ว +14

    Hey, great tutorial! But... while making a project of my own using sockets, I found something interesting I think you should've included: it isn't a good idea to call sockets' send() method more times than needed, because it really affects how much data you can send per second. So, instead of sending the header and the message separately, it's better to do "socket.send(send_length + message)" (once they're both encoded, ofc).
    Found that out after making a simple game using sockets with pygame, where each client's position would have to be sent to the server as fast as possible, and then sent to each client once more. Initially, the clients' positions updated quite slowly; after that change, they updated in almost realtime.
    Love your channel!

  • @Miriam-dk7nm
    @Miriam-dk7nm 4 ปีที่แล้ว +1

    Awesome Tutorial, looking forward to part 2!

  • @736939
    @736939 4 ปีที่แล้ว +3

    Nice intro, please continue the socket programming tutorials, don't jump into another topics. BTW do you have python threading course?

  • @Joshua-dl3ns
    @Joshua-dl3ns 4 ปีที่แล้ว +7

    35:00 In VSCode yes you can run multiple interpreters - in the terminal, you can plus +, and then the box next to the + to show both interpreters

  • @gleeso90
    @gleeso90 4 ปีที่แล้ว +1

    Hi Tim, love your vids. I would like to see a video on Ctypes one day if you get the chance (I.e. wrapping DLLs in a foreign language in python) Keep up the great work, you’re killing it.

  • @furrane
    @furrane 3 ปีที่แล้ว +1

    Excellent video !
    Only a few approximations at the start when discussing networking but that's not a problem since this is not really the main topic of the video.
    Python is on point !
    Congratulations !

  • @thingsiplay
    @thingsiplay 3 ปีที่แล้ว +10

    My entire life changed when I meet you in TH-cam. Again and again.

    • @kebman
      @kebman 3 ปีที่แล้ว +1

      What happened? Did you get hired by TH-cam?

    • @thingsiplay
      @thingsiplay 3 ปีที่แล้ว +2

      @@kebman this guy helped me understanding so many concepts in Python. I am programming all the time since then.

    • @kebman
      @kebman 3 ปีที่แล้ว +1

      @@thingsiplay

  • @cristofersalazar9588
    @cristofersalazar9588 3 ปีที่แล้ว +3

    I'll need to see this more times. ;-;

  • @user-ns8dl3vm5z
    @user-ns8dl3vm5z 4 ปีที่แล้ว +1

    your videos makes curfew easy for me
    big thanks to you
    keep going , much respect 🌹

  • @suyashvashishtha4904
    @suyashvashishtha4904 3 ปีที่แล้ว +1

    Totally awesome Tutorial .. and that's what the reason why i always search for Tech with Tim if i want to learn something... You post awesome content..

  • @kebman
    @kebman 3 ปีที่แล้ว +8

    0:00 to 10:42 is basic networking, modems and and IP's. Skip to 10:43 for the coding.

  • @retr0ds417
    @retr0ds417 4 ปีที่แล้ว +4

    Hey, tim..great work...But I tried using the public IP address and it says af_inet doesn't support this address family...what do I do??

  • @garcand
    @garcand 3 ปีที่แล้ว

    Literally started my python experience with this video

  • @999tktktktk
    @999tktktktk 4 ปีที่แล้ว

    It really helps !!! Thanks a lot !!
    I totally like the way you explain how the whole thing works
    look forward to more your videos about python ~

  • @ethik2933
    @ethik2933 3 ปีที่แล้ว +11

    Hey man, any recommendations on some keywords to search for learning about implementing a good level of security with sockets?

    • @xFrez
      @xFrez 2 ปีที่แล้ว

      I guess you can learn how to secure sockets in theory (not looking for a python examples) and then try to find how to do this in python, probably it will be easier because you will know what to look for.

    • @Erwinsmith94040
      @Erwinsmith94040 2 ปีที่แล้ว +1

      Pls someone suggest me how to connect socket over internet

  • @HIMixoid
    @HIMixoid 4 ปีที่แล้ว +10

    *If you can't see your server from outside of your local network:*
    Most frequent problem you may face while making server reachable over the Internet is port-forwarding.
    In most cases you should go to your router settings and forward your outer port 5050 to local port 5050 of your machine you running the server on. Cuz people who trying to reach you with your public IP litteraly will reach your router.
    So in situation from this video forwarding rules will tell router that if someone will try to connect to its 5050 port it should send 'em to 5050 port of 192.168.1.26 machine and not Macbook.

    • @Aj-hz4dv
      @Aj-hz4dv 4 ปีที่แล้ว

      can you help me, please

    • @HIMixoid
      @HIMixoid 4 ปีที่แล้ว

      @@Aj-hz4dv I can try :)

    • @Aj-hz4dv
      @Aj-hz4dv 4 ปีที่แล้ว

      @@HIMixoid This is my question in Stackoverflow : stackoverflow.com/questions/61069148/how-can-i-send-images-from-the-client-to-the-server-socket-python

  • @farzinkhaledi4394
    @farzinkhaledi4394 2 ปีที่แล้ว

    Thank you so much for this amazing tutorial ,honestly In this 50 minutes tutorial I've learned more then one year at University
    you are great 🙏👍

  • @WisdomIsAwesome
    @WisdomIsAwesome 4 ปีที่แล้ว

    Really fascinating!!! I can make my own server and have client over the public internet or local network send and receive messages across the server and the clients!

  • @Mei8888
    @Mei8888 4 ปีที่แล้ว +6

    Are in Canada separated Modem an Router still a thing? In Germany, Finland (and most other European countries) the modem and the router have been build together in one device. Companies sold them as "Router" but they have build in modems.

    • @CKZA10
      @CKZA10 3 ปีที่แล้ว +1

      Yeah you still get places in the world where they run DSL (internet over phone) or CATV (CAble TV - not to be confused with cat5).
      But even then you run into places where your "router" connects to the ISP "modem" - the ISP "modem" basically terminates the FO and splits up into LAN and Phone with TV coming through as well. Can not really comment on EU - but won't be surprised if it's similar (I'm from South Africa)

  • @5-minute-devops
    @5-minute-devops 3 ปีที่แล้ว

    Very useful and practical session, thank you Tim!

  • @abulaman8713
    @abulaman8713 3 ปีที่แล้ว +1

    Love you man, I just wish ,there were "this-type" of videos for popular libraries like pygame or pyqt.... Instead of just project building ones..... again love you brother

  • @ostfactory4925
    @ostfactory4925 4 ปีที่แล้ว +8

    Hello Tim, just want to add that socket.gethostbyname(socket.gethostname()) might return 127.0.0.1 on linux machines if there is an entry in /etc/hosts file. Removing this entry from the hosts file may cause other installed programs to break, the only reliable way (that I found) of finding the local IP is using a DNS ping.
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))
    SERVER = s.getsockname()[0]
    s.close()
    print(SERVER)
    Hope this helps.

    • @manuelantoniorojasramos5913
      @manuelantoniorojasramos5913 4 ปีที่แล้ว +2

      Thanks, I had been looking for some way to get the IP address instead of just typing it.

    • @ostfactory4925
      @ostfactory4925 4 ปีที่แล้ว +2

      @@manuelantoniorojasramos5913 you're most welcome. Also, please be aware that this method will work only if you are connected to internet (because DNS). Good luck and Happy coding

    • @ron-davin
      @ron-davin 4 ปีที่แล้ว +2

      Thank you! :D

    • @TheDropsofsilver
      @TheDropsofsilver 3 ปีที่แล้ว

      What if the DNS is located somewhere else instead of 8.8.8.8?

    • @ostfactory4925
      @ostfactory4925 3 ปีที่แล้ว

      @@TheDropsofsilver then use that DNS instead of 8.8.8.8.

  • @tcrawford8430
    @tcrawford8430 4 ปีที่แล้ว +12

    Hey Tim how long did it take you to learn the basics to have the ability to build things with python?

    • @tcrawford8430
      @tcrawford8430 4 ปีที่แล้ว

      Mr. Mehi 😂😂😂 man I have a good year before I become a junior in school. By that time I’m going to look into internships., that’s why I asked.

    • @tcrawford8430
      @tcrawford8430 4 ปีที่แล้ว +1

      WORLD-TECH/IT thank you. I just started the basics on Codecademy, I plan on getting the pcep and pcap certs as soon as possible as well.

    • @michaeldamolsen
      @michaeldamolsen 4 ปีที่แล้ว +1

      It depends on your background. If python is your first language it probably takes a few weeks to get started coding things on your own, and a few months before you start to feel at home in the language. If python is your programming language number 23, you can get started in 10-15 minutes. Still, python is unique in several ways that take time to learn, even with experience from 22 other languages. But you just asked about the basics :)

    • @kebman
      @kebman 3 ปีที่แล้ว

      Here's the basics: First, learn about variables and what they do. Learn some types such as numbers and strings. Then learn about conditional statements, which are most commonly 𝚒𝚏 and 𝚎𝚕𝚜𝚎. After that, learn about loops, such as 𝚠𝚑𝚒𝚕𝚎 and 𝚏𝚘𝚛. Then learn about functions, which start with 𝚍𝚎𝚏 (which is short for _definition)_ in Python, and how a function can take a special variable called a parameter. From then on, learn about objects and methods (object orientation). In between, try to learn how to read Python documentation for the various libraries that exist out there. There are also some special pitfalls to know about Python, such as naming the file the same as your 𝚒𝚖𝚙𝚘𝚛𝚝
      statement, for instance.

  • @michaelhans777
    @michaelhans777 3 ปีที่แล้ว

    Man, you're saving my life a lot! Thanks for the tutorial!

  • @rosarubui5410
    @rosarubui5410 3 ปีที่แล้ว +1

    Thank you Tim, that was an awesome tutorial really helped!

  • @arijitghosh6378
    @arijitghosh6378 3 ปีที่แล้ว +3

    The tutorial was really great and I did learn the basics of how to mess around with sockets. I do however have one complaint and that is the method you showed on how to make the server available on the internet. Having the server socket run on the Public IP would never work because multiple devices that are connected to your network share that same Public IP. How would the router know which device to forward that traffic to?
    I looked around on the Internet and Port Forwarding seemed like a viable and easy solution but unfortunately that didnt work.
    So how do we actually get our server socket on the internet?

    • @dannys2290
      @dannys2290 3 ปีที่แล้ว

      Arljit, you would keep you local IP on the server.py application. then you would have to do port forwarding on your router facing the internet. For instance, i would forward all my SSH traffic from destined for port 4545 (public side) and route that traffic internally to my SSH server at 192.168.0.2 on port 22. So everything in my LAN would look like this: ssh user@192.168.0.2 while outside my LAN, it would look like: ssh user@65.34.7.23 -p 4545. For reference, these are Linux commands.

    • @shinydewott
      @shinydewott 3 ปีที่แล้ว

      @@dannys2290 how do we do that with python?

    • @dannys2290
      @dannys2290 3 ปีที่แล้ว

      @@shinydewott port forwarding cannot be done in Python, unless your server is configured as a router using python. If you're looking for that specific information, I wouldn't know how to do that. However port forwarding is a mapping you have to do on your router between external ports going to internal ports pointed at a specific server port.

  • @kebman
    @kebman 3 ปีที่แล้ว +6

    You only need 4 bytes for a message header. This will let you represent numbers up to 4 bytes * 8 bits = 32 bits ^2 = 4,294,967,296 (integer), which is more than enough for chat messages. Given the sometimes small buffer sizes of TCP/IP layers, 64 bytes for a length header is excessive. But not only that, it's _dangerous!_
    As shown before, you can use 64 bytes to represent _astronomical_ numbers, and there's no way in _Hell_ that a chat message will _ever_ be that long unless you sent only noise ... for years(!). But by exploiting a header with so much bloat, it becomes much easier to crack such a naïve implementation of a chat client to construct third party _Denial of Service_ (DOS) attacks. In other words, if any of these bad implementations are found in the wild, they're exploitable by evil hackers.
    So let's say, hypothetically, that a large TCP/IP buffer is about 1 Mb RAM. That's 1,048,576 bytes (and buffers can be much smaller than that). If you use just empty messages from a bad chat implementation, which is using headers that are 64 padded bytes long, then it only takes 1,048,576/64 = 16,384 messages to launch a successful DOS attack, as that is the amount of empty messages you need to fill the buffer.
    Now, that might seem like a lot but it's really nothing to a computer, so it would be a fairly trivial thing to implement, and especially if the chat application has such a bad design flaw. This is why most systems employ other defences against such things, but all it takes to break the first wall, is to infiltrate a poorly programmed chat application. Worst of all, _you'll_ be blamed for it, and not the hacker, since the hacker is merely exploiting your bad code to hide his identity while performing the attack.

    • @bruhhhhh718
      @bruhhhhh718 ปีที่แล้ว +1

      damn dude thanks for this knowledge

    • @markhoo
      @markhoo 11 หลายเดือนก่อน

      666

    • @kebman
      @kebman 11 หลายเดือนก่อน

      @@markhoo 777

  • @achraf_1cy679
    @achraf_1cy679 3 ปีที่แล้ว +1

    you can open multiple terminals in vs code at the same time, nice tutorial btw

  • @anubis_adventure
    @anubis_adventure 2 ปีที่แล้ว +1

    Thank you! with this video I now have a good understanding about sockets programming, before I was so confused about it, I like your detailed explanation. well Done!!!

  • @penewoldahh
    @penewoldahh 3 ปีที่แล้ว +5

    how did you send the file. Is there a way not to have python installed on other devices?

    • @adamcal4257
      @adamcal4257 3 ปีที่แล้ว +1

      I suppose you can convert all of it into .exe in the end, there's a tool for that online.

    • @adamcal4257
      @adamcal4257 3 ปีที่แล้ว

      @@HalfABoolean_Studios
      I actually watched that video, but there's a nice tool that simplifies the process:
      github.com/brentvollebregt/auto-py-to-exe

  • @jasonphilippe8497
    @jasonphilippe8497 ปีที่แล้ว +3

    i have that error client.bind((SERVER, PORT))
    OSError: [WinError 10048] Only one use of each socket address (protocol/network address/port) is usually allowed

    • @Starmanstriker
      @Starmanstriker ปีที่แล้ว

      Make sure 'conn.close()' is outside the while loop. If it is inside of it, the connection will close. (tab back the 'conn.close()' once and it should fix it)

  • @albertovaldez4320
    @albertovaldez4320 4 ปีที่แล้ว

    Omg, what an intro! keep it up man really nice videos

  • @firepygmygaming4409
    @firepygmygaming4409 3 ปีที่แล้ว +6

    ValueError: invalid literal for int() with base 10: 'hello world' still happening need help i used his fix and its still happening

    • @firepygmygaming4409
      @firepygmygaming4409 3 ปีที่แล้ว +1

      Liking this comment dosent help SHIT

    • @mahazikasozi5258
      @mahazikasozi5258 3 ปีที่แล้ว

      yh me to

    • @frostie8802
      @frostie8802 2 ปีที่แล้ว +2

      I think you're converting the string "hello world" into a number. You cannot convert normal text into numbers.
      If you're trying to concatenate a string and a number, use the str() function on the number (or the number variable)
      I hope this helps

  • @rushobinnabi3684
    @rushobinnabi3684 4 ปีที่แล้ว +9

    34:15 age-restriction this man. 😂😂 oh yeah tim. You are connecting to something.

  • @videkrajnc
    @videkrajnc 3 ปีที่แล้ว +1

    Thank you! This was a awesome tutorial!

  • @kobezheng
    @kobezheng 4 ปีที่แล้ว

    Wow! This was extremely helpful!

  • @factorousfactorous3522
    @factorousfactorous3522 4 ปีที่แล้ว +5

    Great video :) It's weird but when I try to bind my public IP adress it raises an error 'Can't assign to requested address', do any of you run into the same issue ?

    • @TechWithTim
      @TechWithTim  4 ปีที่แล้ว +1

      Could be something with your firewall

    • @diegonunez6788
      @diegonunez6788 4 ปีที่แล้ว

      did you fix this? because i am getting the same issue on mac but my firewall is off

    • @andrewrichardson7121
      @andrewrichardson7121 4 ปีที่แล้ว +1

      Hi, just a quick note. You will not be able to bind your public IP (or as we call it external IP address) to your local computer as you are sitting behind the firewall and that NATs (Network Address Translation) and hides your private/internal IP address to the outside world. Your private/internal IP address is non-routable on the internet and as such uses this method. The only way you can do this is to connect your computer directly to the internet but I do not recommend you do this, but if you are adamant you want to do this please ensure you have your computers firewall turned on. There are some other things you need to take into consideration but this is way to detailed for this thread. If any clarification is required please do not hesitate to contact me via this thread.

    • @pxdb8028
      @pxdb8028 3 หลายเดือนก่อน

      @@andrewrichardson7121is this account still active?

  • @dnetne5508
    @dnetne5508 4 ปีที่แล้ว +3

    Not only did I just learn a ton of stuff(it is hard for me to concentrate for a longer periods of time)
    but I also learned about threading
    AND - I did on my Linux machine, I am so happy it worked and I understand most things if not everything now!
    Thank you for existing and doing tutorials like these!
    Just a quick question - how would one encrypt messages(end-to-end?)? I presume I can make up random letter alternatives for my program and like replace each letter within the messages with another one and later reverse it, but I suppose that it would be not that hard to decode..
    Yeah f*** Trump and his no end-to-end encryption, I am not in America and I am against that either way.

    • @legion_prex3650
      @legion_prex3650 ปีที่แล้ว

      congrats. computers are the best, they are better than humans. I only spend my whole time with them. my linux machine is literally my GOD!

  • @TopBagon
    @TopBagon 4 ปีที่แล้ว +2

    Yoooo that new intro is fire nice job

  • @ostfactory4925
    @ostfactory4925 4 ปีที่แล้ว

    Hey Tim, thanks for the great video, one thing that I would also like to point out is that towards the end you said that to make your server accessible over the public network, in addition to replacing your server IP from local to public, one would need to forward the port 5050 in order for the server to listen to the incoming traffic. I'm not a networking expert but depending on the modem / router you are running, it can range from very easy to very hard, plus there are some internet service providers that block port forwarding (including mine). Other option can be to get a static IP and ditch the DHCP.

    • @ostfactory4925
      @ostfactory4925 4 ปีที่แล้ว

      @@croose hi, are the server and client machines on the same network or different? If they are on different networks then you should check your router's manual to see how to forward ports, I really cannot be of much help here as every manufacturer has a different setting in them. But before you even do that, I'd suggest bringing the client and server on the same network and checking if the issue persists or not because you don't need port forwarding in case of same network. If the problem goes away after having both of the machines on the same network then I'd advice checking sites like portforward[dot] com and your router manufacturer's website for more info. Hope this helps

  • @shawnjames3242
    @shawnjames3242 4 ปีที่แล้ว +3

    Hey Tim, when i tried to ran the server.py the second time it gives the following exception:
    OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
    When I changed the port, I can run it. But then I cannot run again on both those ports.
    Can somebody help me with this?

    • @ekremdincel1505
      @ekremdincel1505 4 ปีที่แล้ว

      Error explains everything, this is why we have lots of port. You cant have multiple servers binded on same port at the same time, if you only have one server process be sure you killed old processes successfuly.

    • @shawnjames3242
      @shawnjames3242 4 ปีที่แล้ว

      @@ekremdincel1505 But why didnt that error occur for Tim ?

    • @ekremdincel1505
      @ekremdincel1505 4 ปีที่แล้ว

      @@shawnjames3242 I didnt watch video, did he has 2 server on the same port at a time?

    • @shawnjames3242
      @shawnjames3242 4 ปีที่แล้ว

      @@ekremdincel1505 ya

    • @TechWithTim
      @TechWithTim  4 ปีที่แล้ว

      @@ekremdincel1505 I did not, I had a single server and multiple clients connect to the server

  • @emtydoctrine
    @emtydoctrine 4 ปีที่แล้ว +4

    For reference in regards to ports:
    - Well-known ports: 0 through 1023.
    - Registered ports:1024 to 49151.
    - Dynamic ports: 49152 to 65535
    You will typically use an available port in the registered range such as 8080 or 4443, assuming its not already in use.

  • @automationtesting3149
    @automationtesting3149 3 ปีที่แล้ว

    This is the first time I am learning Python and it is really helpful

  • @automationtesting3149
    @automationtesting3149 3 ปีที่แล้ว

    I am relatively new to Python and this information was really useful

  • @alexwholland
    @alexwholland 3 ปีที่แล้ว +5

    If your are getting the ConnectionRefusedError: [WinError 10061] error try changing the code on the server file from:
    SERVER = socket.gethostbyname(socket.gethostname())
    to:
    SERVER = "your IP adress"

    • @nolans5177
      @nolans5177 3 ปีที่แล้ว

      To add to this, make sure that if using WiFi you set the IPv4 address to a manual address in your network settings and NOT "Obtain IP address automatically". I received this error for hours before I figured out this is what my issue was.

  • @ericorlando9855
    @ericorlando9855 3 ปีที่แล้ว +3

    "Hey, I moved to the right."
    *moves left*

  • @edelinealexandre
    @edelinealexandre 4 ปีที่แล้ว +1

    hi Tim I really enjoy your videos, you're probabely the YT channel which is by now the most usefull in my programming journey !
    I have a request which is : could you make videos as this one but in a more general scale, I mean not based on a specific laguage but just explaining the purpose of a header a handler and all this kind of stuff, because in most tutorial people use those fuction et show what to write but often I dont understand the purpose of each fuction like "what's a writer... how it works...
    Sorry for my poor english

  • @e-danrahamim9397
    @e-danrahamim9397 3 ปีที่แล้ว

    I just had to learn about Socket and my man(Tim) teach it, great

  • @opticalreticle
    @opticalreticle 3 ปีที่แล้ว +3

    how do you get the "run" button on vscode

    • @TalsonHacks
      @TalsonHacks 3 ปีที่แล้ว +1

      Install a code runner extension. I still prefer that you use PyCharm for python 🐍.

  • @agathagu
    @agathagu 3 ปีที่แล้ว +1

    This the video I have been looking for!

  • @Christian-su1nx
    @Christian-su1nx 2 ปีที่แล้ว +1

    Wow I was looking for this and I did not even know it lol. Transitioning to SWEnginering and was wondering how this works and here it is. Thanks!

  • @spokyash
    @spokyash 2 ปีที่แล้ว

    This was such an amazing video! Thank you so much for making this:)

  • @shayavivi3587
    @shayavivi3587 4 ปีที่แล้ว

    Hi first of all I want to thank you. You always make videos on various topics on python.
    Second I would like to ask if you planning on continue the threading series I really like the first videos you made

  • @smabedi
    @smabedi 2 หลายเดือนก่อน

    THIS IS AWESOME! you just solved one of my biggest problems with coding my messenger, thank you man ❤