Java Socket Programming - Multiple Clients Chat
Welcome to WittCode! In this video we will create a group chat using Java sockets. In other words, we will be creating a server with multiple clients using Java sockets. We will also learn about multithreading in Java.
💻 My Software 💻
My Chrome Extension WittCepter - chromewebstore.google.com/det...
📚 My Courses 📚
courses.wittcode.com
👩💻 Download Code 👨💻
blog.wittcode.com
⌛ Timestamps ⌛
0:00 - Demonstrating the Program
2:23 - Creating the IntelliJ Project
2:57 - Coding the Server
9:21 - Coding the ClientHandler
26:45 - Coding the Client
37:47 - Demonstrating the Program
Пікірлер: 283
I think this is the best video on KZread about I/O streams and sockets.
@bernardkingsley8598
3 ай бұрын
Is there any way I can see your code
This truly explains everything so clear, thanks man
This is so exciting!!! I had been trying other tutorials, even paid ones and had problems with all the others. On this one everything went perfect.
Haven't even finished the video yet but I'm happy I found this channel!
Wow man, you really clearly showed how to make such chat in Java, thanks a lot! :)
IT WORKED, THANKS I'VE BEEN LOOKING FOR THIS FOREVER, BUT NO TUTORIAL COULD EXPLAIN IT AS YOU DID
Thank you so much for this video! Very well explained, it helped me a lot for my university project.
Thank you for taking time to explain each step in simple terms. I tried this on my own and was hung up on how each CH object could share 1 updated array list, but then you pointed out the beauty of static variables!
@WittCode
2 жыл бұрын
Thanks so much man! Also love your taste in music haha 🎸
@amc1140
2 жыл бұрын
@@WittCode hell ya Java and Punk Rock are a 90s dynamic duo🤘
@og_yamiatan3957
2 жыл бұрын
@@WittCode can i make those names of clients in diferent color ?
You explain everything so well and simple ♡
THIS IS SO COOL! And I managed to reinforce sockets, IO, AND threads ALL AT ONCE
You are a lifesaver man, thank you a lot you are saving me a ton of hours and nerves :)
So underrated!!! I wish you'll gain more subscribers and viewers. Amazing video
This is what, I looked for in Java. Thank you so.
This dude literally explained my entire 5 months course in a 40 minute video
Wow you are suck a great teacher. You explain every step. Thank you so much!
Lowkey saved my uni lab work xd , keep up the good work !!
Thx for your tutorial, I finally understand how socket work
Great work! I love the thumbnail! So many WittCodes!
@WittCode
3 жыл бұрын
Thanks for the support Freddie! 😎
Very helpful! Thank you so much!
great video thanks for making it i was stuck on this for so long
I understand all men you're a great teacher!!
thank you so much, this content deserves much more credit
@WittCode
2 жыл бұрын
Thanks so much! That means a lot! 😃
Thank you so much!!! This is what I was finding!
I'm so grateful to you, this really so helpful man thank you so much
Thank you! Learned a lot from this
Nice one man. Keep it up!
Thank you very much for this!
Thank you WittCode , you have just earned a new subscriber. I cannot begin to explain how helpful and useful your videos are especially this one. I am a software engineering student and I can safely say that this one video is more useful than my entire Java programming class.
@WittCode
18 сағат бұрын
😀
You are lifesaver man, thank you a lot :)
This is simply awesome man 👍❤️
your video is awesome and helped me a lot. thank you.
Thank you, I had trubles with sending message to multiple clients, because of reading system input, thanks again!
@WittCode
2 жыл бұрын
Hey there thanks so much! Yeah the reading input part tripped me up for a while too! 😃
Let me just tell you one thing. Thanks for Being in KZread to share content most are not capable of doing.
@WittCode
2 жыл бұрын
Thanks so much!
this is briliant my friends thank you so much
This helped me a lot, thanks!
thanks a lot bro, keep the good job.✌
Great video! Really helped!
Great tutorial!
video is very helpful. Thank you.
Great tutorial, thanks
Great video!
thank you! Subscribed!
this was perfect for me thank you
Thanks bro it has been very usefull for me
Thank you very much, man
Great content, learned a lot!
@bernardkingsley8598
3 ай бұрын
Is there anyway I can see your code by chance, that is if it's working
Thank you very much!
very helpful video !
Perfeito bom demais essa aula, ficou muito bom mesmo . Sem enrolação e sem complicação foi ótimo esse tutorial, valeu deixo o meu like e minha inscrição, obrigado
thank uuuuu so much, this is so helpful
Remember to use 'Thread-Safe" collections or manage synchronization in this example.Our static arraylist is a shared resource, and can be accessed by multiple threads simultaneously, where each one can add, remove or read.
Real gem!!
awesome video i love it thankyouu
Nice tutorial man, rly need something like tihs :D
@WittCode
2 жыл бұрын
Thanks so much! Also, love your username lol
Your content is amazing brother, keep it up! I would love to see this video with a GUI integration as you said in the end of the video.
@WittCode
2 жыл бұрын
Thanks so much Kevin! And I will certainly be making a GUI version of this! Probably using JavaFX 😀
@vikaskotwani9573
2 жыл бұрын
@@WittCode , hey witt please do that asap
thank you so much, saved my homework truly!
@ayushsharma4618
7 ай бұрын
bro can you send code please
great video, wonderful explanations throughout too.
@WittCode
18 сағат бұрын
😀
Which design patterns are we using in this program and which pattern I can implement into the code in addition to develop the code?
Very good!
Thank you for the clear and concise explanation. I just subscribed you. I wish to watch your more videos.
@WittCode
18 сағат бұрын
😀
I took a server side approach instead of a client side approach, love the video tho, thank you
Many thanks Sir 😘
thanks for the video
great channel
Isn't it safer to convert public classes to private classes if they are not used in another class? or there is a reason for it? Thank you for this incredible work, your explanations are amazing !😍
What would be the best way to add latency to all the clients receiving a message? Like, if one writes a message, everyone receives it 5s later?
Nice video it was a really nice watch and i learned a bunch of new things from it! Can anyone please explain how to run it in CMD tho? (it looked cool)
is there any difference if we use other io classes such as printwriter, datagramoutput, bufferedoutputstream? I got confused sometimes when I work with other io classes for Java Socket, it doesn't work. The io classes don't input nor output the given string.
thank you soo much
thank you so much...
Great video, loved it. Thank you for explaining the details. Is it possible to implement this structure of group chat with graphical user interface? Actually I tried but I couldn't figure it out. It simply didn't work
hello i have a question, what should i do to make them connect from different pcs and not on localhost. i tried some solutions but it always give me an error
hi, how did you end one client using the command line? At time 2:01. I tried it using Ctrl+C in mac and the server generated a NullPointerException as soon as that client terminated using Ctrl+C
Thanks alot
Extremely thankful for helping us in the easiest ways but, if i want to store every one of the texts sent in a file that stays in the "Server" and whenever a new client joins he/she gets all of the messages printed from the file in the console .. to do that what are the changes i should do?
nice tutuorial man and one silly question "can I connect to that server from another PC?" Or it works only local host?
Life saver
Hello sir. Is the code still on your website? i can only seem to see some Javascript. Is it on a github page?
Is it a TCP or UDP based communication? Really good Video
Why we can't run the server again? After it being in use? Like turn off the server and Re-open it.
Hello question for you sir , I am trying to run in windows cmd but i can t compile the server because of an error about client handler .how exactly you execute this in cmd?
Hey Wittcode.. How do you handle if there are many clients that you cannot spawn each thread for every client on a server?
This is very impressive and it works. I like your approach with clientHandlers. Im a little confused about how multiple clients can connect using the same port. When I did a similar project in C# i got an error saying something like "this port is already in use". Can anyone explain that to me?
how come the same socket in client that sends a message doesn't receive one? I know that we look in arrayList and avoid that but it should work based on the code from the client.java
Hey, Wonderful video its really helpful. I had a question how would you make the Server read the messages that the clients send to each other. When my server reads a msg using bufferedreader it only get the msg that 1 client sent and not the other. Any help would be amazing.
Love the thumbnail hahah
@WittCode
2 жыл бұрын
Sahil! Good to hear from you man! And yeah I thought it was the coolest one Ive made so far lol
I just wanted to say I love your content and how you interact with your fan base but I was also wondering how to run this program from command prompt and how to configure this for use over WAN networks. PS: this tutorial inspired me to make my own chat room project which has been my first real (successful) program.
@WittCode
2 жыл бұрын
Hey John thanks so much for the feedback! To run it over the command prompt you just have to go to where you made the java files and compile it like javac .java and then run it like java . And I have gotten a few questions about making these Java networking programs accessible over the internet and to be honest I am not entirely sure how to do it besides port forwarding or giving your server a public address. Im probably gonna take some time to look into this and make a video on it! 😀
@HAZARD_LIGHTS
2 жыл бұрын
@@WittCode Thank you so much, I really appreciate you taking the time out of your day to respond to my request!
beautiful! thanks! (do more java tutorials pls
Baie dankie oom
Thanks! Can you help me? I can start the client, but the server are closing in few seconds
Tried to adapt this to my game, but only managed to get the server to register the connections, but the clients didnt seem to receive anything. Dunno if the issue was caused by the gui or what.
Can you share the code, not able to find in the link you kept in description
can the client use anathor computer like LAN ???
Helpful video thanks for making this. Can you do a server PC and a client mobile phone.
Thank you so much..!
@WittCode
18 сағат бұрын
😀
Dope, This was really very helpful.
@WittCode
2 жыл бұрын
That's great to hear Althon! Thanks for watching! 😀
Hello, how do I connect the sockets outside the lan to the internet?
Greetings from Ukraine! You are awesome! Thank you so much for this great tutorial. It helped me a lot.
Hi. Thank you for your work. I have some questions. what if i want to send a private message. I will need to creat a new thread for chating with only this client?
Thank you man, is that possible to chat only with one person from the group please share if you have such kind of code