Socket Chatroom client - Creating chat application with sockets in Python

  Рет қаралды 129,812

sentdex

sentdex

5 жыл бұрын

Welcome to part 5 of the sockets tutorial, in this tutorial we're going to build the client's code for our chatroom application.
Text-based tutorials and sample code: pythonprogramming.net/client-...
Channel membership: / @sentdex
Discord: / discord
Support the content: pythonprogramming.net/support...
Twitter: / sentdex
Facebook: / pythonprogramming.net
Twitch: / sentdex
G+: plus.google.com/+sentdex

Пікірлер: 237
@ali_adeeb
@ali_adeeb 5 жыл бұрын
OH GOD me and my friend were looking a perfect tutorial for this like last week and you released these!!! You'll probably go down as the most loved programmer!!
@sentdex
@sentdex 5 жыл бұрын
🥰
@ali_adeeb
@ali_adeeb 5 жыл бұрын
@@sentdex I don't even know what that means but I dont care thanks for replying!!
@sreetamakundu1478
@sreetamakundu1478 4 жыл бұрын
@@ali_adeeb hi
@MyPlaylist-xq8en
@MyPlaylist-xq8en 5 жыл бұрын
I've been waiting for this.....Great Tutorial and Awesome Video!
@karanrandhawa1376
@karanrandhawa1376 5 жыл бұрын
you literally have a video for everything. I LOVE IT
@nikodemus7900
@nikodemus7900 4 жыл бұрын
The moment when you are sure that you have seen all of his mugs... It is an illusion
@weargasm
@weargasm 5 жыл бұрын
You are the number one of python programmers, thanks for sharing.
@DeepakKumar-os4bl
@DeepakKumar-os4bl 5 жыл бұрын
Just for info. If anybody has any difficulty in understanding the code in the video, head over to the text version of the tutorial. It has been explained beautifully. Thanks Harrison :-)
@calebmwaura8631
@calebmwaura8631 4 жыл бұрын
where is the text version buddy??
@kanknw
@kanknw 4 жыл бұрын
@@calebmwaura8631 it's in the description
@calebmwaura8631
@calebmwaura8631 4 жыл бұрын
@@kanknw please send me a link...kindly..
@anirbandey303
@anirbandey303 5 жыл бұрын
I've seen a lot of tutorial videos of many people on many things but your way of explanation is the best! It's clear and simple, I love it.
@sentdex
@sentdex 5 жыл бұрын
Great to hear!
@dmytroohorodnik3562
@dmytroohorodnik3562 5 жыл бұрын
Hell yeah..! Really great tutorial. Exactly what I needed. Wish you good fortune :-)
@vomomediaonline
@vomomediaonline 2 жыл бұрын
I haven’t done this but I am very sure if I do, it’s gonna work ! This is so amazing! It has everything I want, I want to say a very big thank you 🙏🙂 keep it up bro
@wathekghenimi9133
@wathekghenimi9133 5 жыл бұрын
you're a legend thank you so much this is helps me in my project
@user-us7qv1yd4k
@user-us7qv1yd4k 5 жыл бұрын
always love your incredible tea cups)))
@luvkhajuria207
@luvkhajuria207 4 жыл бұрын
for handling client inputs and printing other inputs of other clients at the same time for this, you just have to make input non-blocking. this may help I guess. r_list , _,exe_list = select.select([sys.stdin,client_socket],[],[sys.stdin,client_socket]) for read in r_list: if read == client_socket: msg = client_socket.recv() else: out_msg = sys.stdin.readline().decode('utf8') client_socket.send(out_msg) btw by far best tutorial on sockets and one of the best channel on youtube
@marinaurrey5246
@marinaurrey5246 5 жыл бұрын
Thank you! Very interesting experience. You do good tutorials)
@sentdex
@sentdex 5 жыл бұрын
Happy to share!
@alainachkar9888
@alainachkar9888 3 жыл бұрын
Excellent video series! Thank you!
@georgemavimbela
@georgemavimbela 5 жыл бұрын
this is awesome..thanks I will use this when getting serious on my Python coding lessons
@KushChoudhary
@KushChoudhary 4 жыл бұрын
are u serious now?
@KushChoudhary
@KushChoudhary 4 жыл бұрын
again am here, worried for u. after 1 month
@KushChoudhary
@KushChoudhary 4 жыл бұрын
Hey Friend, I hope u are serious now edit: After 1 month
@dazewaker262
@dazewaker262 Жыл бұрын
Are you serious now ?
@matbaker8294
@matbaker8294 5 жыл бұрын
Great tutorial. Has sent me in the right direction.
@bn_ln
@bn_ln Жыл бұрын
great series - many thanks
@bitcointrader8586
@bitcointrader8586 5 жыл бұрын
Best python youtuber hands down
@marvinwillms5970
@marvinwillms5970 4 жыл бұрын
In your written code for the client there is a typo in the last exception: except Exception as e: # Any other exception - something happened, exit print('Reading error: '.format(str(e))) sys.exit() you're formating but there are no {} inside the string. Love that tutorial, was a lot of fun to build that. Have a good one!
@matsinorge
@matsinorge 4 жыл бұрын
Thank you for this tutorial!! ❤️
@mt.erebus3370
@mt.erebus3370 3 жыл бұрын
Hey sentdex buddy ol' pal, are you considering continuing this tutorial? found it super fun and learned a ton. would love to see gui implementation!
@arozoid
@arozoid 2 жыл бұрын
Check out the Kivy tutorial for GUI implementation.
@lolj2094
@lolj2094 5 жыл бұрын
great stuff as always man
@alainachkar9888
@alainachkar9888 3 жыл бұрын
Could you please explain more about blocking vs non-blocking recv() and how to implement command/response protocols with timeouts?
@Zephyr-tg9hu
@Zephyr-tg9hu 3 жыл бұрын
Awesome tutorial, thanks.
@alpstinger5083
@alpstinger5083 3 жыл бұрын
Thanks man for this awesome tutorial!!!! From where do you learn all this stuff? Because you teach everything so perfectly!
@swiftlyexplained703
@swiftlyexplained703 3 жыл бұрын
It worked! Thank you! :)
@AdiParamartha
@AdiParamartha 5 жыл бұрын
thank you, very helpfull , hopefully i could implement it to iot devices soon
@anchalmallick3335
@anchalmallick3335 4 жыл бұрын
Thankyou! You are my inspiration :)
@ScottUlmer
@ScottUlmer 5 жыл бұрын
+1 on seeing you do this with Qt5 :)
@ruleofthree1733
@ruleofthree1733 5 жыл бұрын
Would be cool if you did a video expanding on this with regards to the server looking for keywords, and then executing a bit of script from a program you've written. Like !roll sent from a user randoms a d6. Or incorperating a little 'mini game' involving another .py file.
@Mutlaq777
@Mutlaq777 5 жыл бұрын
Nice work!
@unix.geektarektalaat1631
@unix.geektarektalaat1631 5 жыл бұрын
Hey, I have a question, how do you interact with each thread ? for instance, if you want to send data from server to a specific client using whatever thread id or anything else. So if server got 3 clients connected, now you want the server to send data to specific client by using thread id or thread ident number or anything. I tried and failed. Can you guide me ?
@samuelgriffin1955
@samuelgriffin1955 4 жыл бұрын
Thanks, really helpful
@AMOs-sy8vl
@AMOs-sy8vl 5 жыл бұрын
Still you are working with us thank you
@frbuccoliero
@frbuccoliero 5 жыл бұрын
"Cool!" Part 2 the revenge of the cold
@hichambenhammouda7368
@hichambenhammouda7368 3 жыл бұрын
really great tutorial, I actually took your idea and used a Tkinter GUI for it. I have one question though , if say like I want the server to make a list of all connected clients and broadcast that list so it can be shown in the client GUI and ofcours it would be continuously update.. how can I do that ?
@josej.camposzeledon3127
@josej.camposzeledon3127 5 жыл бұрын
Amazing!
@Mzkysti
@Mzkysti 4 жыл бұрын
Great Socket tutorial, thanks. It kept me wondering is it possible to run these in Sublime Text?
@Rasinasrok
@Rasinasrok 4 жыл бұрын
It says "Reading error [WinError 10035] A non-blocking socket operation could not be completed immediately" and the connection closed immediately from the server.
@everton.colombo
@everton.colombo 4 жыл бұрын
For those of you interested, I made a GUI version of this using tkinter that also constantly checks for new messages. Here, have a look: github.com/Everton-Colombo/Socket-Chatroom
@sentdex
@sentdex 4 жыл бұрын
Please provide attribution for the socket bits
@ATXpert
@ATXpert 4 жыл бұрын
if i want to make the application public to download, and a private chat(person to person) how do i know which ports are open for use in the clients system, and also i suppose i need to make a server that will connect between two clients, by username. main question is how do i know which ports are ready to use
@judeleon8485
@judeleon8485 4 жыл бұрын
Great tutorial. Where can find the server and client code scripts written in this tutorial?
@wompytompylompyshompy
@wompytompylompyshompy 3 жыл бұрын
I love your videos and actually highly appreciate it if you would teach us (I'm a total python noob just following the steps of the tutorial) how to put this in a GUI.
@jake2663
@jake2663 3 жыл бұрын
The tkinter library might be a good place to start for simplicity but QT is better
@imagineexistance4538
@imagineexistance4538 5 жыл бұрын
For the message receiving without input try _thread or if you don’t have it as a module look at threading(I use pythonista and have _thread but pythonista has different things).and try and make the output and input functions because the module runs two functions and tuples of them(if no input use (,)), The module will continuously run both simotaniously, it is not perfect but works good on my projects, try it out with a copy, it may work or completely break the code
@myeg841
@myeg841 3 жыл бұрын
nice work
@ScottUlmer
@ScottUlmer 5 жыл бұрын
Hey I found a way to attach it into a UI. The biggest "issue" is that I had to break your While True and instead had it look for new messages every 1 second. While there might be some lag (literally up to a second), I find this more than useful to people who would be following these tutorials. Just so you know I simply took your code and modified it to work with a .ui file. Using a .ui with Qt Designer is very user-friendly. If you are interested in what I made let me know.
@wesleywithrow3524
@wesleywithrow3524 4 жыл бұрын
He has a tutorial on how to create a UI for this using Kivy.
@Bvic3
@Bvic3 10 ай бұрын
In case you don't like the weird way to convert with f-strings/strip to manage bytes, here is another version: bytes_header = int.to_bytes(len(bytes_message), HEADER_LENTH, "big") int_header = int.from_bytes(bytes_header, "big") And to convert utf8-string to bytes: bytes_data = bytes(data, "utf-8") utf8_data = bytes_data.decode("utf-8")
@pra8eek
@pra8eek 4 жыл бұрын
Great tutorial! Is the GUI video uploaded yet?
@devallazzydevs8544
@devallazzydevs8544 4 жыл бұрын
Its a great video...can you tell me how to run python file from the local server to client server? or is there any other ways to run python file?
@aashabtajwarkhan2501
@aashabtajwarkhan2501 4 жыл бұрын
Help Please! After running the server, I open a client and give my username there. But when I open a second client(and give the username there) and try to send a message from the first client, the following error shows up Traceback (most recent call last): File "client.py", line 44, in client_socket.send(message_header + message) ConnectionResetError: [Errno 104] Connection reset by peer It would be really great if someone could point out where the mistake was!
@zaferkacmaz8214
@zaferkacmaz8214 4 жыл бұрын
bro you are amazing
@Jonas-odt
@Jonas-odt 4 жыл бұрын
Greate video! Question will this code be able to control the clients pc? like run commands in the command line and such? Thanks!
@ottop1377
@ottop1377 3 жыл бұрын
no.
@YashovardhanJha
@YashovardhanJha 4 жыл бұрын
which ip have you put in the client and server file when you are connecting with other machines on other networks
@lbxmega6574
@lbxmega6574 4 жыл бұрын
How can I connect to the server from another computer? I have tried multiple IP’s and received various errors such as “no connect route” and “host error”. Anyway I can connect a remote device to my server?
@mihirbhudia4064
@mihirbhudia4064 4 жыл бұрын
I am very confused atm. I have followed your exact code, even copy and pasted the code from your website, but I do not seem to get the "new client connection" message. Does anyone have any possible reason for this that there could be?
@sanasm3359
@sanasm3359 4 жыл бұрын
u actually save me ! that is my project for university but in which video u have worked on UI?
@Fuzti13
@Fuzti13 2 жыл бұрын
Could someone explain to me what the ":
@yorozuya6115
@yorozuya6115 4 жыл бұрын
Nice tutorial, can I send message from server to clients? without block?
@bubbachubs8224
@bubbachubs8224 4 жыл бұрын
How do I make this actually work across multiple computers, so that I can actually talk to other people and not myself
@eddied.3426
@eddied.3426 4 жыл бұрын
This is great. Could you make a tutorial on how to make a video chat program? Info on the web seems scarce on this point. Also, how do you connect server to clients over the internet?
@johncarcher
@johncarcher Жыл бұрын
To get the server to connect clients over the internet, I'd say set the server to the IP of your internet router then get the clients to set their IPs to the routers then the Server will listne to the routers port and the clients will connect to the routers port.
@MstrangerGaming
@MstrangerGaming Ай бұрын
i know this is an old video but the logic still works, now the question is , if i want to make this public (connection with different network) then how the connection will work
@hx9d674
@hx9d674 5 жыл бұрын
So there is or isn't way to make chat automatically updated when new message is recived?
@richyuh
@richyuh 4 жыл бұрын
How is the client code exiting out of the while True: # receive things and not stuck in an infinite loop? Thank you for the tutorial
@bcddd214
@bcddd214 4 жыл бұрын
I totally used/sponged this.
@pedrocdo9599
@pedrocdo9599 4 жыл бұрын
Awasome tutorial
@ottop1377
@ottop1377 3 жыл бұрын
how do i make this work accross multiple computers? i've tried using a hamachi server but it just doesnt connect. even my own ipv4 address doesnt work, it says the ip is not valid in its context. can someone please help?
@Froggles_
@Froggles_ 4 жыл бұрын
Can you please write the code into the comment section or the description because I’m really struggling to keep up on everything you are doing thank you:)
@sanjaytp9410
@sanjaytp9410 4 жыл бұрын
Hey, did the vid for creating the GUI part of a chat room get posted on youtube..?
@KushChoudhary
@KushChoudhary 4 жыл бұрын
i will be making that with source code sooner
@nuklearboysymbiote
@nuklearboysymbiote 5 жыл бұрын
in your text-based tutorial you didn't import sys, might want to fix that
@caseycruz7959
@caseycruz7959 Жыл бұрын
Is there a way that the client can pick who they want to send a message to if there are more than two clients?
@juandiegofm
@juandiegofm 3 жыл бұрын
I simply love these tutorials. just a couple of things...You said that you wish that you don't have to go to your folder and then initialize client and server by using the CMD...well...just doble click the py files and that's all :) 2. Can you please do an example by using an EXTERNAL server like a server in dreamhost or any other provider? that would be GREAT since there are SSL issues that I would like to see how you handle them. Thanks for your time and amazing work.
@shinydewott
@shinydewott 3 жыл бұрын
I know this is an old video, but I've been trying to host a game I've been working online to play with a friend. I have managed to get the sockets to work on my local internet but I can't find any explanation on how to do it online.
@gamhcrew556
@gamhcrew556 2 жыл бұрын
will your program work if the client and server programs are running from different devices?
@DestinyCreatesEntertainment
@DestinyCreatesEntertainment 4 жыл бұрын
on the website you forgot to import sys. also, unused import statement select on client
@waiwaiwai8179
@waiwaiwai8179 4 жыл бұрын
When i send more than two messages, error shows up :( Could anyone help me with that? Error shown in server: Traceback (most recent call last): File "C:/Users/Administrator/PycharmProjects/chatroom/chatserver.py", line 55, in user = clients[notified_socket] KeyError: Process finished with exit code 1
@voidling2496
@voidling2496 3 жыл бұрын
i put a wait for a key to get pressed before the message thing so you have to press a key to send a message but it updates automaticly if you dont type noting os dependent
@dariusvladescu9341
@dariusvladescu9341 4 жыл бұрын
how do i print something at the same time while requesting user input
@ishaanverma1268
@ishaanverma1268 5 жыл бұрын
Ayyy he switched to sublime
@JPJROBBO137
@JPJROBBO137 4 жыл бұрын
yOU doing this from memory omg
@no5x937
@no5x937 5 жыл бұрын
Excellent Series on Python 3 Sockets. I got it to work with the Server in one terminal and one Client in another terminal. When I add a 2nd Client, the Server recognizes it and also receives messages. But the two Clients don't recognize each other and they eventually exit from a General Error invalid literal for int() with base 10: 'Hello Serv' Any ideas?
@ravindramohith7082
@ravindramohith7082 Жыл бұрын
yeah same error any soln for this prob?
@Strawberry-oz1qu
@Strawberry-oz1qu 2 жыл бұрын
Please continue this series, I tried both Threading and Multiprocessing but the message from the other side doesn't come simultaneously. Please make a video and guide us.
@nishtha7597
@nishtha7597 4 жыл бұрын
Nyc tutorial..can you please make a tutorial how to connect it with face recognition for more security. I need to do this in my project but can't find any tutorial for that.
@ZemZem
@ZemZem 4 жыл бұрын
Sentdex, is it possible to make a socket with bluetooth on PC (Using AF_BLUETOOTH) ? because I always get an error saying that there is nothing called AF_BLUETOOTH, and when I made a search I found that some people claimed that bluetooth socket with python is not supported in Windows ...
@alejandroburgosjimenez1582
@alejandroburgosjimenez1582 4 жыл бұрын
hi, i use your program as a base for a project. Im trying to comunicate two raspeberry pi but when i run the client program in the other pi the error ERROR 111 CONECTION REFUSED pops out. plzzz help
@megarayamegaraya5024
@megarayamegaraya5024 3 жыл бұрын
Hey Sir thank for the Great Video!, i enjoyed from beginning until the very end. I got a question Sir, why whenever i do 2 client and chat one to another the Prompt gives error "Invalid Literal for int() with base 10:" how do i fix this?
@megarayamegaraya5024
@megarayamegaraya5024 3 жыл бұрын
nvm i found a typo ! thanks again !
@liuyang9483
@liuyang9483 3 жыл бұрын
can we make two threads that one is for sending and the other is for receiving so that you dont have to press enter to check any incoming msg. It just shows up.
@HT79
@HT79 3 жыл бұрын
yep, that's one way to do it
@rydxz6149
@rydxz6149 Жыл бұрын
How to make the messages pop up instant?
@gerardtoudji2634
@gerardtoudji2634 2 жыл бұрын
BIG UP
@santhoshxd
@santhoshxd 5 жыл бұрын
bro when are you going to do the GUI? btw Very nice video brooo...helped a lot!!!
@sentdex
@sentdex 5 жыл бұрын
Already did, with Kivy, here: pythonprogramming.net/introduction-kivy-application-python-tutorial/
@miguelgrigoleti9788
@miguelgrigoleti9788 Жыл бұрын
Na parte do cliente da para fazer todas as importações de uma vez assim: import socket, select, errno
@zdrasbuytye
@zdrasbuytye 4 жыл бұрын
can I run this codes on ubuntu shell ? and what IDE are you using ?
@jonathanmarx752
@jonathanmarx752 3 жыл бұрын
HI, I tried running it from 2 different computers and it didn't work. how should I change it so it works between different computers?
@jaffryjaman4951
@jaffryjaman4951 5 жыл бұрын
Hello , do you have any plans to make a series on computational fluid dynamics ? The thing is that i am familiar with python , but there are limited tutorials on how to use the python modules used for computational fluid dynamics. It would be very useful if you made a tutorial series on cfd for the aeronautical engineering communities . Thanks
@menandmice
@menandmice 5 жыл бұрын
Computational fluid dynamics is an extremely theoretical area of science. A sort of rocket science. To make tutorials about that and Python would demand lots of time and expertise. Many, many months.
@jaffryjaman4951
@jaffryjaman4951 5 жыл бұрын
@@menandmice thanks for letting me know
@happymonkey1703
@happymonkey1703 4 жыл бұрын
Hey um i have a problem, my client is having trouble connecting with the server, well the server is not printing out the part where it said accepted new connection... . This video is great help!
@ottoyang
@ottoyang 4 жыл бұрын
Try turning off your antivirus, That also happened to me
@viktor3512
@viktor3512 4 жыл бұрын
Hey, if i want to do the same chat as you did, but I'd like to chat with my friend via the network, what should I change? Thanks in advance
@jonathanmarx752
@jonathanmarx752 3 жыл бұрын
hi, im trying to do that now, what did you change to make it work?
@rhulanimogotsi6869
@rhulanimogotsi6869 2 жыл бұрын
How do I keep the socket open in the background to accept any incoming messages, even if the app isn’t open
@johncarcher
@johncarcher Жыл бұрын
Great video, only 1 issue with the code. How could I make it so that it constantly refreshes so I don't have to send a message in order to receive new ones if that makes sense. Basically if I send a message then person 2 sends a message, I would have to send a message to receive the message that they sent me.
@samdose4672
@samdose4672 4 жыл бұрын
Couldn't you just use threading to update the incoming messages without being blocked by the input?
@xCleverton
@xCleverton 4 жыл бұрын
would like to know how this could be done
@vacha7106
@vacha7106 3 жыл бұрын
what do i do i got this error General error int() argument must be a string, a bytes-like object or a number, not 'builtin_function_or_method'
@Aragubas
@Aragubas 3 жыл бұрын
i have an entire gui framework made with pygame, it has multi threading features and runs on both windows and linux, so i gonna try making a discord clone x3 using this base xD
Python Sockets Simply Explained
39:33
NeuralNine
Рет қаралды 155 М.
When You Get Ran Over By A Car...
00:15
Jojo Sim
Рет қаралды 12 МЛН
Khó thế mà cũng làm được || How did the police do that? #shorts
01:00
Please be kind🙏
00:34
ISSEI / いっせい
Рет қаралды 192 МЛН
Gzip is all You Need! (This SHOULD NOT work)
19:47
sentdex
Рет қаралды 150 М.
GUI Applications For All Platforms with Flet in Python
11:08
NeuralNine
Рет қаралды 38 М.
Simple TCP Chat Room in Python
25:39
NeuralNine
Рет қаралды 210 М.
Python Socket Programming Tutorial
49:43
Tech With Tim
Рет қаралды 1 МЛН
🌐 Network Programming in Rust - Building a TCP Server
21:55
File Transfer via Sockets in Python
14:44
NeuralNine
Рет қаралды 56 М.
The AI wars: Google vs Bing (ChatGPT)
18:41
sentdex
Рет қаралды 108 М.
Open Source AI Inference API w/ Together
25:25
sentdex
Рет қаралды 30 М.
When You Get Ran Over By A Car...
00:15
Jojo Sim
Рет қаралды 12 МЛН