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

  • @f3sa899
    @f3sa8992 жыл бұрын

    I think this is the best video on KZread about I/O streams and sockets.

  • @bernardkingsley8598

    @bernardkingsley8598

    3 ай бұрын

    Is there any way I can see your code

  • @uuo4930
    @uuo49302 жыл бұрын

    This truly explains everything so clear, thanks man

  • @cybernetic777
    @cybernetic777 Жыл бұрын

    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.

  • @weaponkid1121
    @weaponkid11212 жыл бұрын

    Haven't even finished the video yet but I'm happy I found this channel!

  • @pawe7420
    @pawe74202 жыл бұрын

    Wow man, you really clearly showed how to make such chat in Java, thanks a lot! :)

  • @MostafaMahmoud-cj2sh
    @MostafaMahmoud-cj2sh Жыл бұрын

    IT WORKED, THANKS I'VE BEEN LOOKING FOR THIS FOREVER, BUT NO TUTORIAL COULD EXPLAIN IT AS YOU DID

  • @jadabouzeid9165
    @jadabouzeid91652 жыл бұрын

    Thank you so much for this video! Very well explained, it helped me a lot for my university project.

  • @amc1140
    @amc11402 жыл бұрын

    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

    @WittCode

    2 жыл бұрын

    Thanks so much man! Also love your taste in music haha 🎸

  • @amc1140

    @amc1140

    2 жыл бұрын

    @@WittCode hell ya Java and Punk Rock are a 90s dynamic duo🤘

  • @og_yamiatan3957

    @og_yamiatan3957

    2 жыл бұрын

    @@WittCode can i make those names of clients in diferent color ?

  • @irinatrandafir7390
    @irinatrandafir73902 жыл бұрын

    You explain everything so well and simple ♡

  • @UninspiredFilm5
    @UninspiredFilm5Ай бұрын

    THIS IS SO COOL! And I managed to reinforce sockets, IO, AND threads ALL AT ONCE

  • @maxhitmemedi6598
    @maxhitmemedi65982 жыл бұрын

    You are a lifesaver man, thank you a lot you are saving me a ton of hours and nerves :)

  • @spenzr6920
    @spenzr6920 Жыл бұрын

    So underrated!!! I wish you'll gain more subscribers and viewers. Amazing video

  • @mosesfrancis4976
    @mosesfrancis4976 Жыл бұрын

    This is what, I looked for in Java. Thank you so.

  • @GiyuTomiokaTheOneAndOnly
    @GiyuTomiokaTheOneAndOnly Жыл бұрын

    This dude literally explained my entire 5 months course in a 40 minute video

  • @motodankz4838
    @motodankz4838 Жыл бұрын

    Wow you are suck a great teacher. You explain every step. Thank you so much!

  • @oveezion
    @oveezion2 жыл бұрын

    Lowkey saved my uni lab work xd , keep up the good work !!

  • @jackinquisitor9645
    @jackinquisitor9645 Жыл бұрын

    Thx for your tutorial, I finally understand how socket work

  • @freddiewittmann1494
    @freddiewittmann14943 жыл бұрын

    Great work! I love the thumbnail! So many WittCodes!

  • @WittCode

    @WittCode

    3 жыл бұрын

    Thanks for the support Freddie! 😎

  • @g.722
    @g.7222 жыл бұрын

    Very helpful! Thank you so much!

  • @harrygabbi5181
    @harrygabbi51812 жыл бұрын

    great video thanks for making it i was stuck on this for so long

  • @wenwengalarpe14344
    @wenwengalarpe1434410 ай бұрын

    I understand all men you're a great teacher!!

  • @tungle3635
    @tungle36352 жыл бұрын

    thank you so much, this content deserves much more credit

  • @WittCode

    @WittCode

    2 жыл бұрын

    Thanks so much! That means a lot! 😃

  • @mc_mzcgt
    @mc_mzcgt2 жыл бұрын

    Thank you so much!!! This is what I was finding!

  • @rnyah_
    @rnyah_ Жыл бұрын

    I'm so grateful to you, this really so helpful man thank you so much

  • @borissmax3
    @borissmax3 Жыл бұрын

    Thank you! Learned a lot from this

  • @uzumakiuchiha7678
    @uzumakiuchiha7678 Жыл бұрын

    Nice one man. Keep it up!

  • @akalankaalutwela7712
    @akalankaalutwela77122 жыл бұрын

    Thank you very much for this!

  • @xxx4am
    @xxx4am5 ай бұрын

    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

    @WittCode

    18 сағат бұрын

    😀

  • @angelinawho5551
    @angelinawho55512 жыл бұрын

    You are lifesaver man, thank you a lot :)

  • @haris7521
    @haris75212 жыл бұрын

    This is simply awesome man 👍❤️

  • @charlesjaussaud1822
    @charlesjaussaud18222 жыл бұрын

    your video is awesome and helped me a lot. thank you.

  • @martingogaming1777
    @martingogaming17772 жыл бұрын

    Thank you, I had trubles with sending message to multiple clients, because of reading system input, thanks again!

  • @WittCode

    @WittCode

    2 жыл бұрын

    Hey there thanks so much! Yeah the reading input part tripped me up for a while too! 😃

  • @imanjallali8258
    @imanjallali82582 жыл бұрын

    Let me just tell you one thing. Thanks for Being in KZread to share content most are not capable of doing.

  • @WittCode

    @WittCode

    2 жыл бұрын

    Thanks so much!

  • @vasantpatel9297
    @vasantpatel92972 жыл бұрын

    this is briliant my friends thank you so much

  • @replikvltyoutube3727
    @replikvltyoutube37272 жыл бұрын

    This helped me a lot, thanks!

  • @adwa1888s
    @adwa1888s3 ай бұрын

    thanks a lot bro, keep the good job.✌

  • @mihaioprea9398
    @mihaioprea93982 жыл бұрын

    Great video! Really helped!

  • @Tygelin86
    @Tygelin86Ай бұрын

    Great tutorial!

  • @chetan788
    @chetan788 Жыл бұрын

    video is very helpful. Thank you.

  • @AlexKayzProductions
    @AlexKayzProductions2 жыл бұрын

    Great tutorial, thanks

  • @elishaamenuveve4307
    @elishaamenuveve43072 жыл бұрын

    Great video!

  • @karolinemalko1723
    @karolinemalko17232 жыл бұрын

    thank you! Subscribed!

  • @freddierobinson9587
    @freddierobinson9587 Жыл бұрын

    this was perfect for me thank you

  • @sirojiddingroup
    @sirojiddingroup Жыл бұрын

    Thanks bro it has been very usefull for me

  • @kurwa_mach
    @kurwa_mach2 жыл бұрын

    Thank you very much, man

  • @arthurbakker740
    @arthurbakker7403 ай бұрын

    Great content, learned a lot!

  • @bernardkingsley8598

    @bernardkingsley8598

    3 ай бұрын

    Is there anyway I can see your code by chance, that is if it's working

  • @johnnys.828
    @johnnys.8282 жыл бұрын

    Thank you very much!

  • @long3850
    @long3850 Жыл бұрын

    very helpful video !

  • @damiaotiktok023
    @damiaotiktok0236 ай бұрын

    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

  • @aladin7339
    @aladin73392 жыл бұрын

    thank uuuuu so much, this is so helpful

  • @romanzdev
    @romanzdev5 ай бұрын

    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.

  • @vishnusudarsanam5375
    @vishnusudarsanam53752 жыл бұрын

    Real gem!!

  • @heshakarathnasekara7135
    @heshakarathnasekara71352 жыл бұрын

    awesome video i love it thankyouu

  • @Asswipe69
    @Asswipe692 жыл бұрын

    Nice tutorial man, rly need something like tihs :D

  • @WittCode

    @WittCode

    2 жыл бұрын

    Thanks so much! Also, love your username lol

  • @kevincianci5443
    @kevincianci54432 жыл бұрын

    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

    @WittCode

    2 жыл бұрын

    Thanks so much Kevin! And I will certainly be making a GUI version of this! Probably using JavaFX 😀

  • @vikaskotwani9573

    @vikaskotwani9573

    2 жыл бұрын

    @@WittCode , hey witt please do that asap

  • @hvasomhelst
    @hvasomhelst7 ай бұрын

    thank you so much, saved my homework truly!

  • @ayushsharma4618

    @ayushsharma4618

    7 ай бұрын

    bro can you send code please

  • @bhpure30
    @bhpure304 ай бұрын

    great video, wonderful explanations throughout too.

  • @WittCode

    @WittCode

    18 сағат бұрын

    😀

  • @elifkaragoz2606
    @elifkaragoz26062 жыл бұрын

    Which design patterns are we using in this program and which pattern I can implement into the code in addition to develop the code?

  • @americancitizen748
    @americancitizen7484 ай бұрын

    Very good!

  • @premkarki2
    @premkarki24 ай бұрын

    Thank you for the clear and concise explanation. I just subscribed you. I wish to watch your more videos.

  • @WittCode

    @WittCode

    18 сағат бұрын

    😀

  • @0brooo
    @0brooo2 жыл бұрын

    I took a server side approach instead of a client side approach, love the video tho, thank you

  • @mahamatmahamatabdoulaye893
    @mahamatmahamatabdoulaye8932 жыл бұрын

    Many thanks Sir 😘

  • @kutayyaman
    @kutayyaman2 жыл бұрын

    thanks for the video

  • @danielluo6499
    @danielluo64992 жыл бұрын

    great channel

  • @user-hr3wf9rn9o
    @user-hr3wf9rn9o Жыл бұрын

    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 !😍

  • @LighterST
    @LighterST2 жыл бұрын

    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?

  • @15iunie94
    @15iunie94 Жыл бұрын

    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)

  • @ihsannuruliman3656
    @ihsannuruliman36562 жыл бұрын

    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.

  • @m.misbahalizada9837
    @m.misbahalizada98372 жыл бұрын

    thank you soo much

  • @vedant5541
    @vedant55412 жыл бұрын

    thank you so much...

  • @ismailgunduz7
    @ismailgunduz72 жыл бұрын

    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

  • @aladin7339
    @aladin73392 жыл бұрын

    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

  • @ritchiemaegamot9460
    @ritchiemaegamot94605 ай бұрын

    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

  • @nordeenhasan6030
    @nordeenhasan60302 жыл бұрын

    Thanks alot

  • @wasiuddinbhuyian5081
    @wasiuddinbhuyian5081 Жыл бұрын

    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?

  • @or.abylaikhan
    @or.abylaikhan2 жыл бұрын

    nice tutuorial man and one silly question "can I connect to that server from another PC?" Or it works only local host?

  • @diogofernandes7625
    @diogofernandes76252 жыл бұрын

    Life saver

  • @feuerherz007
    @feuerherz0072 жыл бұрын

    Hello sir. Is the code still on your website? i can only seem to see some Javascript. Is it on a github page?

  • @sebastiangard18
    @sebastiangard182 жыл бұрын

    Is it a TCP or UDP based communication? Really good Video

  • @3umaryy
    @3umaryy Жыл бұрын

    Why we can't run the server again? After it being in use? Like turn off the server and Re-open it.

  • @radupop625
    @radupop6252 жыл бұрын

    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?

  • @vivekreddy8551
    @vivekreddy85512 жыл бұрын

    Hey Wittcode.. How do you handle if there are many clients that you cannot spawn each thread for every client on a server?

  • @bobfarker4001
    @bobfarker4001 Жыл бұрын

    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?

  • @igormanolescu5910
    @igormanolescu59104 ай бұрын

    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

  • @ahamedinhaam906
    @ahamedinhaam9062 жыл бұрын

    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.

  • @sahilbhirud1301
    @sahilbhirud13012 жыл бұрын

    Love the thumbnail hahah

  • @WittCode

    @WittCode

    2 жыл бұрын

    Sahil! Good to hear from you man! And yeah I thought it was the coolest one Ive made so far lol

  • @HAZARD_LIGHTS
    @HAZARD_LIGHTS2 жыл бұрын

    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

    @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

    @HAZARD_LIGHTS

    2 жыл бұрын

    @@WittCode Thank you so much, I really appreciate you taking the time out of your day to respond to my request!

  • @kutilkol
    @kutilkol Жыл бұрын

    beautiful! thanks! (do more java tutorials pls

  • @schalkvisagie5671
    @schalkvisagie5671 Жыл бұрын

    Baie dankie oom

  • @iopersonelweb
    @iopersonelweb2 жыл бұрын

    Thanks! Can you help me? I can start the client, but the server are closing in few seconds

  • @mige5fin
    @mige5fin2 жыл бұрын

    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.

  • @yashwanth7978
    @yashwanth7978 Жыл бұрын

    Can you share the code, not able to find in the link you kept in description

  • @noobmaster0810
    @noobmaster08102 жыл бұрын

    can the client use anathor computer like LAN ???

  • @wenwengalarpe14344
    @wenwengalarpe1434410 ай бұрын

    Helpful video thanks for making this. Can you do a server PC and a client mobile phone.

  • @Jaa1711
    @Jaa1711Ай бұрын

    Thank you so much..!

  • @WittCode

    @WittCode

    18 сағат бұрын

    😀

  • @AlthonJohnson
    @AlthonJohnson2 жыл бұрын

    Dope, This was really very helpful.

  • @WittCode

    @WittCode

    2 жыл бұрын

    That's great to hear Althon! Thanks for watching! 😀

  • @carjavsos1173
    @carjavsos11732 жыл бұрын

    Hello, how do I connect the sockets outside the lan to the internet?

  • @nadiiar75
    @nadiiar752 жыл бұрын

    Greetings from Ukraine! You are awesome! Thank you so much for this great tutorial. It helped me a lot.

  • @greenman3846
    @greenman38462 жыл бұрын

    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?

  • @ambawadisu2050
    @ambawadisu20502 жыл бұрын

    Thank you man, is that possible to chat only with one person from the group please share if you have such kind of code