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

Поделиться
HTML-код
  • Опубликовано: 3 янв 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 🙂🙏

  • @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 ☺️

  • @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 🤠

  • @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

  • @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 😊

  • @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!

  • @christinehu5323
    @christinehu5323 10 месяцев назад +1

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

    • @BekBrace
      @BekBrace  10 месяцев назад

      Thank you so much for watching, my friend

  • @helloparviz
    @helloparviz 4 месяца назад +1

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

    • @BekBrace
      @BekBrace  4 месяца назад

      @@helloparviz I'm glad my friend 🙏

  • @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

  • @ayushdaga4742
    @ayushdaga4742 2 года назад +2

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

    • @BekBrace
      @BekBrace  2 года назад

      Thank you Ayush ☺️

  • @arbibenmaatoug5566
    @arbibenmaatoug5566 Год назад +1

    Magnificant explanation , thanks.

  • @codingbeast6927
    @codingbeast6927 Год назад +1

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

    • @BekBrace
      @BekBrace  Год назад

      👍 Enjoy my friend

  • @swagmasterj
    @swagmasterj 2 года назад +1

    Excellent vid man! Thanks so much

    • @BekBrace
      @BekBrace  2 года назад

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

  • @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!

  • @HadesMrDark
    @HadesMrDark 3 года назад +2

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

    • @BekBrace
      @BekBrace  3 года назад +1

      Thanks MrDark , glad you liked it 🙂

  • @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

  • @mithra05jk
    @mithra05jk 6 месяцев назад +1

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

    • @BekBrace
      @BekBrace  6 месяцев назад

      @@mithra05jk My pleasure 🙂

  • @hackandcode3474
    @hackandcode3474 3 года назад

    You can tell he knows what hes doing great work

  • @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

  • @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

  • @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 ❤️❤️ 🙏

  • @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 🙂

  • @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 🍻

  • @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

  • @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

  • @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 6 месяцев назад

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

    • @divanvanzyl7545
      @divanvanzyl7545 6 месяцев назад

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

  • @MasterChi__
    @MasterChi__ 2 года назад +1

    Awesome video!!!!!!!!!

  • @happychoices4156
    @happychoices4156 Год назад +1

    great thank you, just to check what is bash

  • @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

  • @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

  • @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

  • @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 ?

  • @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 🙂

  • @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.

  • @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

  • @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

  • @imaneimane1806
    @imaneimane1806 2 года назад +1

    Very very thank you

    • @BekBrace
      @BekBrace  2 года назад

      You're welcome, Imane

  • @Pinkman3000
    @Pinkman3000 Год назад +1

    😎

  • @alaamohamad3104
    @alaamohamad3104 Год назад

    How u open (git bash here)

  • @ninabeinzo771
    @ninabeinzo771 4 года назад +1

    very cool !

  • @elackiyasakthivel2002
    @elackiyasakthivel2002 2 года назад

    Which ide?

    • @BekBrace
      @BekBrace  2 года назад

      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

  • @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

  • @ЭмметтБраун-у3т
    @ЭмметтБраун-у3т 8 месяцев назад +1

    today I created my application using a socket

  • @datastructure_solved5839
    @datastructure_solved5839 3 года назад

    Bestttt

  • @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