Python Network Programming #3: TCP Chat Room (Server and Multiple Clients)

Поділитися
Вставка
  • Опубліковано 9 лют 2025

КОМЕНТАРІ • 132

  • @yonisapir6270
    @yonisapir6270 2 роки тому +10

    This was a great tutorial, I love how you explained each step and each function and parameter, this is exactly what I was looking for and struggling with the most. Thank you so much dude!

    • @BekBrace
      @BekBrace  2 роки тому +2

      Yoni my friend, so glad you liked it 🙂🙏

  • @leonkennedy6726
    @leonkennedy6726 4 роки тому +7

    oh wow this is a gem 💎 in an ocean ! Thanks Bek and keep doing these networking video series

    • @petitboucle8077
      @petitboucle8077 4 роки тому

      Agree!

    • @BekBrace
      @BekBrace  4 роки тому +1

      Thank you very much for such kind words , I appreciate it !

    • @kgCode658
      @kgCode658 2 роки тому

      @@BekBrace I didn't sub any python channel but I will sub you coz ur awesome explaination

  • @Moribunde
    @Moribunde 2 роки тому +4

    you're a god, I've been looking how to do exactly that in a lot of places and none of them described it so easily. ❤

    • @BekBrace
      @BekBrace  2 роки тому +1

      Thanks so much my friend for the compliment 😊 I'm a simple human being 🤠

  • @MounirSMalak
    @MounirSMalak 4 роки тому +4

    Flawless!! You deserve more views ! Love the section division too - keep it up buddy

    • @BekBrace
      @BekBrace  4 роки тому

      Mourir S. Malak Thank you so much 😊

  • @White_GLoves
    @White_GLoves Рік тому +1

    Oh,you're so kind.almost reply to every comment.I am a colloge student from China and I appreciate the video so much.

    • @BekBrace
      @BekBrace  Рік тому

      Thank you so much my friend, and best of luck to you in your studies ☺️

  • @riteshchaudhary7784
    @riteshchaudhary7784 2 роки тому +1

    Thank you so much Bek! I found your code on github but I was unable to understand it, then I searched on YT and then found this 💎 of a playlist !

    • @BekBrace
      @BekBrace  2 роки тому +1

      Hey Ritesh 🙂 Thank you!

  • @helloparviz
    @helloparviz 5 місяців тому +1

    wonderful video! all things that I've needed from socket module. thank you very much.

    • @BekBrace
      @BekBrace  5 місяців тому

      @@helloparviz I'm glad my friend 🙏

  • @christinehu5323
    @christinehu5323 11 місяців тому +1

    thanks so much for this toturial, absolutly amazing!!!!!!!!!!!

    • @BekBrace
      @BekBrace  11 місяців тому

      Thank you so much for watching, my friend

  • @ayushdaga4742
    @ayushdaga4742 2 роки тому +2

    Loved it man! Thanks for creating this tutorial series :)

    • @BekBrace
      @BekBrace  2 роки тому

      Thank you Ayush ☺️

  • @codingbeast6927
    @codingbeast6927 2 роки тому +1

    Thanks for these videos i was think about learning this for some time

    • @BekBrace
      @BekBrace  2 роки тому

      👍 Enjoy my friend

  • @arbibenmaatoug5566
    @arbibenmaatoug5566 Рік тому +1

    Magnificant explanation , thanks.

  • @HadesMrDark
    @HadesMrDark 4 роки тому +2

    This is a perfect video, thank you for your work.

    • @BekBrace
      @BekBrace  4 роки тому +1

      Thanks MrDark , glad you liked it 🙂

  • @swagmasterj
    @swagmasterj 2 роки тому +1

    Excellent vid man! Thanks so much

    • @BekBrace
      @BekBrace  2 роки тому

      You're welcome, Jeremy 😊 and Thank You for watching

  • @atifshakeel1982
    @atifshakeel1982 Рік тому +1

    Excellent video and explanation... I am new to network programming but grasped this very quickly bcz of the easy way of explaining each and every step.

    • @BekBrace
      @BekBrace  Рік тому

      Great 😃👍 Thanks so much

  • @mithra05jk
    @mithra05jk 7 місяців тому +1

    oh my god thanks a lot this is exactly what i was looking for

    • @BekBrace
      @BekBrace  7 місяців тому

      @@mithra05jk My pleasure 🙂

  • @hackandcode3474
    @hackandcode3474 3 роки тому

    You can tell he knows what hes doing great work

  • @HankeyMassacre
    @HankeyMassacre 3 роки тому +1

    I love you really, I figured how this works after a couple days searching for that clear explaintation. Sadly you dont have videos how to implement crash fault tolerance, reliable ordered multicast, voting and dynamic discovery of hosts :(

    • @HankeyMassacre
      @HankeyMassacre 3 роки тому

      Do you have maybe good sources for those topics? I sadly dont find nothing good stuff :(

    • @BekBrace
      @BekBrace  3 роки тому

      @@HankeyMassacre if you mean books, then no , but these topics are all over the web

  • @high_fly_bird
    @high_fly_bird 2 роки тому +1

    thanks, it was great help for mu studies!

    • @BekBrace
      @BekBrace  2 роки тому

      Thank you Olga 😊 Glad you found it useful

  • @kshitijchaudhari9932
    @kshitijchaudhari9932 3 роки тому

    Thankyouu ...It's amazingggg ! ....Loved it !!

    • @BekBrace
      @BekBrace  3 роки тому

      So glad to hear my friend

  • @imadaboudaher1689
    @imadaboudaher1689 3 роки тому +1

    you are a amazing thanks i learned alot from you

    • @BekBrace
      @BekBrace  3 роки тому +1

      Thanks a lot, Gamer, means a lot to me 🙂

  • @MasterChi__
    @MasterChi__ 2 роки тому +1

    Awesome video!!!!!!!!!

  • @thewayofodin4574
    @thewayofodin4574 3 роки тому +5

    Thank you for this video! Very easy to understand for python n00bs like myself.
    I had a few questions if you have the time;
    1. Is there a way to eliminate the senders typed message, to prevent it from doubling on the senders screen?
    2. Is there a way to prevent user messages that are posted when you are typing from showing up in the message you are writing?
    3. Any possibility of a follow up vid with login/encryption? :D
    Again, thank you.

    • @BekBrace
      @BekBrace  3 роки тому +1

      Thanks a lot , appreciate it 😊
      Regarding the first 2 questions; we can absolutely tweak in the code to hide messages ( sender/receiver ) to avoid double appearance but this was just for demonstration purpose :)
      As far as a follow up video for a login mechanism, I can’t promise in the near future but I’ll add it to my YT projects list :)

    • @thewayofodin4574
      @thewayofodin4574 3 роки тому +1

      @@BekBrace Much appreciated sir. Thank you!

  • @imaneimane1806
    @imaneimane1806 2 роки тому +1

    Very very thank you

    • @BekBrace
      @BekBrace  2 роки тому

      You're welcome, Imane

  • @ninabeinzo771
    @ninabeinzo771 4 роки тому +1

    very cool !

  • @Majed_ashraf
    @Majed_ashraf 2 роки тому +2

    It says established connection with so and so but immediately shows error in alias.recv and the error is
    "An existing connection was forcibly closed by the remote host"

    • @BekBrace
      @BekBrace  2 роки тому

      Have you tried to search for that error on the internet in stack overflow or Google ?

    • @Majed_ashraf
      @Majed_ashraf 2 роки тому

      Yes i did
      I didn't reply earlier because i don't want to sound stupid infront of you so i made my search.
      Turns out i forgot to start the client thread because i didn't add receive_thread.start() at the client side

    • @Majed_ashraf
      @Majed_ashraf 2 роки тому

      Talk about not wanting to sound stupid 🤣

    • @justintime4187
      @justintime4187 2 роки тому

      @@Majed_ashraf I have receive_thread.start() in my code but im still getting that same error message

  • @justinwking
    @justinwking 3 роки тому +1

    This tutorial has been very helpful, but I can't figure out how to shut the server down. Do you have any advice??

    • @BekBrace
      @BekBrace  3 роки тому +1

      Thank you, Justin.
      Yes, you need to call 2 methods whenever you want to shut down the server : shutdown() and close().
      You can create a function and call it at the end of your code block :
      def terminate(): server.shutdown(socket.SHUT_RDWR)
      server.close()
      Don’t forget the indentation in terminate() function

  • @Pinkman3000
    @Pinkman3000 Рік тому +1

    😎

  • @danielbd6490
    @danielbd6490 4 роки тому +2

    Hey good video, I did the chat room in my network
    How can I do it using computers from other networks?

    • @BekBrace
      @BekBrace  4 роки тому +1

      Hi Daniel !
      Your question is a tough one 😄
      There will be a lot of caveats to tackle down the road : 1- some configuration on the router of the computers on that other LAN .
      The reason is that nowadays everybody has a public IP address that is provided by your ISP ( internet service provider) This IP address is not fixed, but it is easy to lookup what is ur ip (whatismyip.com)
      2 - sending is not going to be a problem, but receiving is. Some service providers like here in Poland don't allow just any port to be used and you have to find out which ports are allowed. The well known ports are most likely not allowed. That for instance makes it impossible to host a webserver without first contacting your ISP.
      It’s really not easy and require some experience in networking
      I’ll try in the future to answer your question with a live demo using sockets in python - thanks for your question, Daniel

    • @danielbd6490
      @danielbd6490 4 роки тому

      @@BekBrace Thank you 😁👍

    • @BekBrace
      @BekBrace  4 роки тому +1

      @@danielbd6490 No worries , if you’ve got any questions just let me know - cheers 🍻

  • @hatemhatem6571
    @hatemhatem6571 2 роки тому +1

    how can i request a list of the aliases for all other connected clients ? in the client ??

    • @BekBrace
      @BekBrace  2 роки тому +1

      Hey Hatem. I'll find a solution And will let you know

    • @hatemhatem6571
      @hatemhatem6571 2 роки тому

      @@BekBrace ❤️❤️ 🙏

  • @metalnick749
    @metalnick749 3 роки тому +1

    Nice Tutorial. Is it possible for clients to connect with different ips?

    • @BekBrace
      @BekBrace  3 роки тому +1

      Thanks man ; yes but it would be very difficult to achieve this + for which purpose ?

    • @metalnick749
      @metalnick749 3 роки тому

      @@BekBrace Thanks for your respond. Just for chat. For example, me the host start the server and my friends can connect and chat.

    • @BekBrace
      @BekBrace  3 роки тому

      @@metalnick749Ok got you now ; it’s very tough but possible
      There will be a lot of problems to tackle down the road : 1- some configuration on the router of the computers on that other LAN .
      The reason is that nowadays everybody has a public IP address that is provided by your ISP ( internet service provider) This IP address is not fixed, but it is easy to lookup what is ur ip (whatismyip.com)
      2 - sending is not going to be a problem, but receiving is. Some service providers like here in Poland don't allow just any port to be used and you have to find out which ports are allowed. The well known ports are most likely not allowed. That for instance makes it impossible to host a webserver without first contacting your ISP.
      It’s really not easy and requires some experience in networking

  • @juni8031
    @juni8031 3 роки тому +1

    i ran this once and it was running perfectly but now i keep getting this error (OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted) whats that about?

    • @juni8031
      @juni8031 3 роки тому

      ohhhh I get it now, the port was active all I had to do was change it. It's working now :)

    • @BekBrace
      @BekBrace  3 роки тому +1

      @@juni8031 اهلا ريم و اسف علي التاخر في الرد - مرحبا بك في اى وقت 🙂
      And I’m glad it’s working ok now- cheers

    • @juni8031
      @juni8031 3 роки тому

      @@BekBrace la 3adi, used this as reference for my school project :) thanks 7bebe!

  • @lukaspfeiffer179
    @lukaspfeiffer179 2 роки тому +1

    Very nice ! But does anyone know why I don't get the chat updated in my git bash window(s)? They only update if I (from this git bash window) write a message. ... One of my clients is started in pycharm. There I have live chat update the way the git bash instances have it in the video.

    • @BekBrace
      @BekBrace  2 роки тому

      Hello Lukas. Thank you for your comment 😊 can you rephrase your question cause I didn't quite understand

    • @lukaspfeiffer179
      @lukaspfeiffer179 2 роки тому

      @@BekBrace Yes, let's say I have three clients 1. "Git Bash A Client", 2. "Git Bash B Client" and 3. "Pycharm Client" (which only means this time I run the code directly in pycharm and not from git bash or cmd line or so). And the server is of course running.
      Problem is: "Git Bash A Client" sends message: Despite of the broadcast functionality of the server, only my "Pycharm Client" directly sees the message. "Git Bash B Client" is not updated with the text sent by "Git Bash A Client". But obviously anywhere in the background of "Git Bash B Client" the message must have been received because when I now send a message from "Git Bash B Client" the moment I press "ENTER" the old messages appear. I mean it's not really relevant for what I want to do but I asked my self what's the problem here...Maybe my git bash Version. I don't know. Best regards from MUC, GER

  • @divanvanzyl7545
    @divanvanzyl7545 3 роки тому +1

    Bro I'm trying to host a chat server like that on the internet. All tutorials just run the server on local machine. What can one use?

    • @BekBrace
      @BekBrace  3 роки тому

      Hey Divan 👋
      There will be a lot of problems to tackle down the road if you want to host it online:
      1- some configuration on the router of the computers on that other LAN .
      The reason is that nowadays everybody has a public IP address that is provided by your ISP ( internet service provider) This IP address is not fixed, but it is easy to lookup what is ur ip (whatismyip.com)
      2 - sending is not going to be a problem, but receiving is. Some service providers like here in Poland don't allow just any port to be used and you have to find out which ports are allowed. The well known ports are most likely not allowed. That for instance makes it impossible to host a webserver without first contacting your ISP.
      It’s really not easy and requires some experience in networking

    • @divanvanzyl7545
      @divanvanzyl7545 3 роки тому

      @@BekBrace Hi thanks for the reply. But I cannot host it on my machine/router due to the way my ISP works. Incomming connections will never reach my router as a result.
      What I am looking for is a cloud solution. I have experience with deploying a C# webAPI to Azure (app service) but it seems that a TCP server like this, is not that easy!

    • @user-kg1mw9ld9o
      @user-kg1mw9ld9o 7 місяців тому

      did you ever figure it out? im trying to do the same

    • @divanvanzyl7545
      @divanvanzyl7545 7 місяців тому

      @@user-kg1mw9ld9o Yes, I used the Azure SignalR service. SignalR is a C# library, its essentislly an abstraction layer over websockets.

  • @happychoices4156
    @happychoices4156 Рік тому +1

    great thank you, just to check what is bash

  • @lloydaugustine7367
    @lloydaugustine7367 2 роки тому

    The write thread glitches on my end, was there an update recently that possibly caused this? When ran on my raspberry pi, it crashes

    • @BekBrace
      @BekBrace  2 роки тому

      Hey. As far as I know, no updates, but I don't think that running on pi would cause a crash; do you get an error message of some sort ?

  • @loulouxie
    @loulouxie 2 роки тому

    What do I need to put on the client file if the server is on another computer on the same wifi network ?

    • @BekBrace
      @BekBrace  2 роки тому

      It is almost impossible

  • @RAMY322
    @RAMY322 3 роки тому

    Hi man, my two questions may seem dumber than the others which have been asked. For creating this chatroom, I don't need a Python server like on PythonAnywhere, OpenShift, and all the other Python servers hosting services, right? And this chatroom only works for people on my LAN or on my own PC only? Because I can see it running on localhost

    • @BekBrace
      @BekBrace  3 роки тому +1

      You can ask anything you want my friend :)
      For creating a a server using Python, you can only use socket programming like show in the demonstration.

  • @datastructure_solved5839
    @datastructure_solved5839 3 роки тому

    Bestttt

  • @kgCode658
    @kgCode658 2 роки тому

    thank you so much.. can you plz tell me how to disconnect client from the chatroom??

    • @kgCode658
      @kgCode658 2 роки тому

      and if we want to connect client with other specific client only how to approach it??

    • @BekBrace
      @BekBrace  2 роки тому +1

      Hey Tech Tok. As far as I'm aware this is very easily done using Django channels. Unfortunately, I don't have django channels course or tutorial on the channel, but I might consider doing one just to show you how to connect a client - client or to disconnect a client from the chatroom

    • @kgCode658
      @kgCode658 2 роки тому

      @@BekBrace that will be so helpful.. thx btw for detailed explaination

  • @FaridCenreng-
    @FaridCenreng- 3 роки тому

    I got a task to built the same program, but in udp. Is it still using the same way?

    • @BekBrace
      @BekBrace  3 роки тому

      I doubt that , the core nature of tcp and udp is totally different, because udp doesn’t establish a connection before data is sent while tcp is connection focused protocol

  • @xugestory
    @xugestory 3 роки тому +1

    how to modify it so it work over the internet?????

    • @BekBrace
      @BekBrace  3 роки тому +1

      This works only on localhost, it's not publicly available. I've answered this question many times, so one of my answers was :
      There will be a lot of caveats to tackle down the road : 1- some configuration on the router of the computers on that other LAN .
      The reason is that nowadays everybody has a public IP address that is provided by your ISP ( internet service provider) This IP address is not fixed, but it is easy to lookup what is ur ip (whatismyip.com)
      2 - sending is not going to be a problem, but receiving is. Some service providers like here in Poland don't allow just any port to be used and you have to find out which ports are allowed. The well known ports are most likely not allowed. That for instance makes it impossible to host a webserver without first contacting your ISP.
      It’s really not easy and require some experience in networking

  • @REVERSE_ENGINE
    @REVERSE_ENGINE 2 роки тому +1

    Can this program to set GUI

    • @BekBrace
      @BekBrace  2 роки тому

      Yes absolutely , in fact I was thinking of refactoring the code while adding a UI to it 🙂

  • @ЭмметтБраун-у3т
    @ЭмметтБраун-у3т 9 місяців тому +1

    today I created my application using a socket

  • @REVERSE_ENGINE
    @REVERSE_ENGINE 3 роки тому

    This program can not chat between 2 computers .On one computer can only have two cmd panels

    • @BekBrace
      @BekBrace  3 роки тому +1

      That’s it yes.
      Or if on the same network.

    • @REVERSE_ENGINE
      @REVERSE_ENGINE 2 роки тому

      ​@@BekBrace winError 10061

  • @alaamohamad3104
    @alaamohamad3104 Рік тому

    How u open (git bash here)

  • @elackiyasakthivel2002
    @elackiyasakthivel2002 3 роки тому

    Which ide?

    • @BekBrace
      @BekBrace  3 роки тому

      That’s not IDE, it’s code editor : Visual Studio Code

  • @REVERSE_ENGINE
    @REVERSE_ENGINE 3 роки тому

    erorr - OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

    • @BekBrace
      @BekBrace  3 роки тому

      Yes, so make sure that the port you’re using isn’t active otherwise you have to change it so the connection can work

    • @REVERSE_ENGINE
      @REVERSE_ENGINE 3 роки тому

      @@BekBrace How to make this work in real time

    • @REVERSE_ENGINE
      @REVERSE_ENGINE 3 роки тому

      @@BekBrace server is not working

    • @REVERSE_ENGINE
      @REVERSE_ENGINE 3 роки тому

      now ok sorry .my terminal erorr

  • @lavender0666
    @lavender0666 Рік тому

    this looks like the code from neuralnine

    • @BekBrace
      @BekBrace  Рік тому

      What's your point (if you have any?) and what does neurlanine mean ?
      In any case, this is the standard setup for multiple clients consumption and one local server in Python.

  • @imaneimane1806
    @imaneimane1806 2 роки тому +1

    Very very thank you

    • @BekBrace
      @BekBrace  2 роки тому

      You're very welcome