How To Create a Chat App and Server Tutorial WPF C#

Sdílet
Vložit
  • čas přidán 7. 09. 2024
  • Here is a tutorial showing you how to create a chat app and a chat server using WPF and C# which can also be used to create a game server in order to make a multiplayer game using C# WPF but the game can be made in Unity
    this networking tutorial will show you how to create network packets, using TCP, which includes the TCPListener and TCPClient in order to make a chat app using C# programming and the WPF Framework, reading and writing binary data
    using a network stream as well as a memorystream to create the network buffer, this tutorial includes events in order to make it slightly event driven. There is a video on my channel which features a modern professional chat app design
    which you can follow and add to this project.
    Discord: / discord
    Patreon: / payloads
    Chat App Professional Modern Design: • WPF C# Professional Mo...

Komentáře • 158

  • @kay23456
    @kay23456 Před 2 lety +54

    This man has a video on how to make a discord ui as well as how to create a chat app.... he essentially just gave the power of remaking discord to everyone

  • @YidingHe
    @YidingHe Před 2 lety +21

    As an experienced Java developer, I love these video tutorials that can take me into new languages quickly and efficiently.

  • @FiveNineO
    @FiveNineO Před 2 lety +14

    The programming gods have blessed us brethren!

  • @energy-tunes
    @energy-tunes Před měsícem +1

    amazing, modern c# networking content seems to be lacking, this is a nice breath of fresh air

    • @_buffer
      @_buffer  Před 28 dny

      I'm glad you found it useful! :-)

  • @Worthical
    @Worthical Před 2 lety +5

    I swear my computer listens to my conversations and recommends this video and I aint mad at all!

  • @DemHP.
    @DemHP. Před rokem +21

    For everyone who doesn't wanna write out the code at 6:25 here you go:
    namespace ChatClient.MVM.Core
    {
    class RelayCommand : ICommand
    {
    private Action execute;
    private Func canExecute;
    public event EventHandler CanExecuteChanged
    {
    add { CommandManager.RequerySuggested += value; }
    remove { CommandManager.RequerySuggested -= value; }
    }
    public RelayCommand(Action execute, Func canExecute = null)
    {
    this.execute = execute;
    this.canExecute = canExecute;
    }
    public bool CanExecute(object parameter)
    {
    return this.canExecute == null || this.canExecute(parameter);
    }
    public void Execute(object parameter)
    {
    this.execute(parameter);
    }
    }
    }

    • @kaanderin8382
      @kaanderin8382 Před rokem +1

      i have 3 errors in this code idk why i did exactly same with video
      my errors are those
      ICommand
      CommandManager
      CommandManager
      can you help me

    • @drewcumpton1232
      @drewcumpton1232 Před rokem +3

      @@kaanderin8382 Sounds like you need to add the namespace ' using System.Windows.Input; ' at the top. All 3 of those errors are in that namespace.

    • @kaanderin8382
      @kaanderin8382 Před rokem +1

      @@drewcumpton1232 thank you man

    • @hubertromario4874
      @hubertromario4874 Před rokem

      Where is the Icommadns interface file?

    • @rfatisler6500
      @rfatisler6500 Před rokem +1

      @@hubertromario4874 using System.Windows.Input

  • @drewcumpton1232
    @drewcumpton1232 Před rokem +9

    Great Vid, very instructional. One thing I would like to add, in the Packet Builder under the Write Message module, when using VS 17.4, you have to add 1 line to it, where you actually create a buffer and get a buffer length to get it to work properly. Well, at least for me this was the case, it may be a .Net version discrepancy also since 5.0 is no longer supported any more.
    public void WriteMessage(string msg)
    {
    byte[] buff = BitConverter.GetBytes(msg.Length);
    _ms.Write(buff, 0, buff.Length);

  • @Frusko
    @Frusko Před 2 lety +15

    I absolutely love these videos. Please keep doing stuff like this, just watching you do stuff like this is helping me pick up better habits :D

    • @_buffer
      @_buffer  Před 2 lety +2

      That makes me so happy to hear! And More videos are coming your way! :-)

  • @user-ib1kw2ip7c
    @user-ib1kw2ip7c Před rokem +3

    Thank you so much. Your video helped a lot with my course project. I wouldn't have figured it out without you.

    • @_buffer
      @_buffer  Před rokem +1

      I'm so glad you found this useful!

  • @barryjohnson2756
    @barryjohnson2756 Před 2 lety +8

    Please continue to make videos like witch you create small wpf apps with their cool design. I hope you make a wpf app with database like SQlite and made a customer like app where you add/modify/delete/filter into database.That will be very helpful for me and a lot of people as well.

    • @_buffer
      @_buffer  Před 2 lety +2

      More on the way! :-)

  • @oxygenfn5224
    @oxygenfn5224 Před rokem +3

    You saved my programming class test, thank you so much, cant wait to see more of your videos I also learned so many new things :)

  • @ErenCode
    @ErenCode Před 2 lety +4

    Better than my lectures! xD

  • @DangDucCoder
    @DangDucCoder Před 10 měsíci +3

    How to display multiple chat windows? My code is the same as in the video but it only displays 1 mainwindow window? Please help me answer. Please. Thanks

  • @boost5207
    @boost5207 Před 2 lety +8

    This is amazing man. Thank you :) Definetily going to use this in my course project :)

  • @AkarumeiAkashi
    @AkarumeiAkashi Před rokem +4

    1) It`s literally magnificent! Thank you so much, keep making such videos plz!
    2) How did you set-up the color theme in your visual studio, look`s great!
    3) Can this chat communicate over the Internet (computers are in different networks)?
    Thanks for video, one more time!

    • @drewcumpton1232
      @drewcumpton1232 Před rokem +3

      It should be able to, 1 person can have the server, just make sure it uses your outside IP address, and unused port. Everyone else would need the client, and to have the correct IP address and port number to connect properly. And if the server is on a home network, you will need to make sure port forwarding for the selected port is forwarding to the correct internal IP address.

  • @ramzykaram296
    @ramzykaram296 Před rokem

    This is one of the greatest tutorials ever, as a python developer that was the best tutorial on C#, sockets, and MVVC

  • @all-dj
    @all-dj Před 2 lety +5

    Senpai noticed me

    • @_buffer
      @_buffer  Před 2 lety +5

      Thai student has been noticed!

  • @Cognitionz
    @Cognitionz Před 2 lety +1

    Brilliant ^-^ Would love to see how to make a custom "server" for a group of people to join.

  • @alisaeidalsheikh6451
    @alisaeidalsheikh6451 Před 2 lety +1

    thats so cool 😎
    Sir don’t you plan make full tutorial for C# form Beginning to advanced 🙏

  • @Foxyzier
    @Foxyzier Před 2 lety +2

    Maybe a follow up video with sending something like a message object with attachments, and to cache them on the client with the message history?

  • @MoviesChannelHdmovies4523
    @MoviesChannelHdmovies4523 Před 3 měsíci +1

    How to display the multiple windows? Pls teach me i need this program 🙏🏻

    • @_buffer
      @_buffer  Před 3 měsíci

      Feelf ree to join the Discord and we can discuss it further :-)

  • @Hadouken77
    @Hadouken77 Před 2 lety +7

    Hello, how did you create two instances of the MainWindow at around 38:25?

    • @_buffer
      @_buffer  Před 2 lety +4

      Good question! I opened up the bin folder and started the .exe from there :-)

    • @user-ph9zp3fs5r
      @user-ph9zp3fs5r Před 2 lety +3

      in visual stidio you can rightclick a project and click debug then click start new instance and it will put another instance in debug mode instead if just openning an exe

  • @tacqz
    @tacqz Před 2 lety +2

    Could you explain to me what the methods of the RelayCommand do? Just to understand it instead of just copying it?

    • @AshishPandey-zo6wd
      @AshishPandey-zo6wd Před 5 měsíci

      its kindda boiler code , so you have to mention it for the xaml and code to interact properly.

  • @mohanadkiswany9501
    @mohanadkiswany9501 Před rokem +1

    how can we make the clients are able to send a private message, i.e. they are able to select one of the users in the chat room in some way and only the designated user will receive the message?

  • @wearetheroyalsgames1464

    Great video thanks, this will really help with learning C# !
    p.s.
    at 31.06 with i got a error CS0052:
    public PacketReader PacketReader;
    i fixed it by making the:
    public class Server
    to an
    internal class server
    I don't know if anyone else got this problem or im just stupid, but if anyone got troubles with it you can try this.

  • @HighSkillxD
    @HighSkillxD Před 2 lety +7

    Hello, I have a problem at 19:25. MemoryStream.Write need 3 parameter (byte[] buffer, int offset, int count). But in the video you only pass one parameter. Is there a solution for this?

    • @Shin_v2
      @Shin_v2 Před 2 lety

      Make sure that you are using .NET 5 or 6 (Core) and not .NET 4.X Framework.

    • @drewcumpton1232
      @drewcumpton1232 Před rokem

      If you are using .NET 4.x framework, you can do the following:
      public void WriteMessage(string msg)
      {
      byte[] buff = BitConverter.GetBytes(msg.Length);
      _ms.Write(buff, 0, buff.Length);

  • @pedramkavian
    @pedramkavian Před 8 měsíci +1

    Maybe it's too late to question, but it seems to be a very simple text message app. What do you do when client wants to send different kinds of messages. Let's say he's sending a video to server. It's going to take a while until all bytes are sent to server and while sending the video he's going to send a text message as well. So, how your server is going to recognize what messages it's reading? Because it was busy reading the video data. Or maybe you must use another TcpClient for such scenarios?

    • @_buffer
      @_buffer  Před 8 měsíci

      Good question!
      And compression the video is always a good idea, and another possibility is to create a thread per client and have ti run all of it's own work.

  • @DarkCloud0000
    @DarkCloud0000 Před 2 lety +1

    I love your videos they are nice ideas to work on👌🏻💙

  • @kaiserdrache7675
    @kaiserdrache7675 Před rokem +1

    As of 27:00 the username can only be 4 characters in length, otherwise the server is forcfully shut down. I hope you fix this further in the video.

    • @nguyenhuuhanhlam
      @nguyenhuuhanhlam Před 9 měsíci

      small bug at WriteMessage func in PacketBuilder class, ms.Write(Encoding.ASCII.GetBytes(msg), 0, msg.Length); (not buff.Length)

  • @dra4hos757
    @dra4hos757 Před 2 lety +2

    the best one bro thanks a lot

    • @_buffer
      @_buffer  Před 2 lety +1

      You're most welcome :-)

  • @wanderingtf2314
    @wanderingtf2314 Před 2 lety +1

    What were the usings for the RelayCommand class? You didn't show them in the video.

  • @michalligezka5439
    @michalligezka5439 Před rokem

    I finished writing out all of the code as in the video, everything works except for the messaging - it doesn't get sent through to the console or the program

  • @ajyoldhamala
    @ajyoldhamala Před 6 měsíci +2

    How are you creating multiple instances of the running project?

    • @_buffer
      @_buffer  Před 6 měsíci

      Good question! You could either set up the project to debug that way, or head into the bin folder and run another instance that way by running the executable. :-)

  • @HSS-pq6pi
    @HSS-pq6pi Před rokem

    Hello I enjoyed your wonderful lecture! But how do I connect this chat app on another computer?

  • @farrightcentrist7565
    @farrightcentrist7565 Před 2 lety

    Thanks for the great tutorial mate☺️

  • @ousstechfr5107
    @ousstechfr5107 Před 2 lety +2

    Great work, just a question, why you didn't use signalR ( or for learning purpose ) ?

    • @_buffer
      @_buffer  Před 2 lety +2

      Good question! Overly complicated for creating something so simple, as well as the fact that it just adds a bunch of unecessary abstraction while at the same time limiting the development experience, the only time I would actually use SignalR would be if I wanted to live update something in a web application :-)

    • @ousstechfr5107
      @ousstechfr5107 Před 2 lety +4

      ​@@_buffer you got a point, even if i disagree

    • @_buffer
      @_buffer  Před 2 lety +4

      @@ousstechfr5107 To each their own, whatever floats your boat and works for the project! :-)

  • @qee5339
    @qee5339 Před rokem

    i'm just stuck in that moment 8:05 if in video it at least showed error, in my situation it looks like it's not working at all because i have no error, no "connected" text (i decided to follow video a bit further cause i thought maybe program is working but it's not) it seems like a binding is not working, do i have to maybe install something on my visual or something else i simply have no clue how to make it work correctly

  • @venom_ftw9316
    @venom_ftw9316 Před rokem +1

    Hi, thank you so much for this tutorial it has really helped me.
    However, I have a bug I cannot seem to fix. Whenever I send a packet, three characters of the string are omitted. My packet Reader and packet Builder classes are exactly the same as yours, as is most of the code I am using
    The issue gets solved when I just add three to the message length but I want a more solid solution. Thank you

    • @_buffer
      @_buffer  Před rokem

      Hi! I'm glad you found it useful, it would be much easier to assist you on Discord :-)

    • @venom_ftw9316
      @venom_ftw9316 Před rokem

      @@_buffer thank you for responding, I found out that the issue was because I called the wrong function 😂😂

  • @yoyteibe8720
    @yoyteibe8720 Před 2 lety +3

    Hey, great video overall but
    how do you not get errors for ICommand and CommandManager?

    • @dhruvakikkeri6217
      @dhruvakikkeri6217 Před 2 lety +1

      I got those errors too

    • @Xsnipe
      @Xsnipe Před 2 lety +2

      add "using System.Windows.Input;" to the top

    • @ayyrax4154
      @ayyrax4154 Před rokem

      @@Xsnipe u jus saved me bruv thank you

  • @julie2586
    @julie2586 Před 2 lety +2

    Hey, is there a way for two computers on the same wifi to connect to the same server? I tried to change the IP address to my own but that doesn't work.

    • @_buffer
      @_buffer  Před 2 lety

      Should work just fine, feel free to hop on the Discord server and send me a message and I'll happily look into it! :-)

    • @imrxzey
      @imrxzey Před 2 lety

      did you find out, cause i cant either

  • @swathy6819
    @swathy6819 Před 2 lety +2

    maybe a video on creating an animated wpf application?

    • @_buffer
      @_buffer  Před 2 lety +2

      That's actually on my list of video ideas! :D

  • @sparrowin6570
    @sparrowin6570 Před 5 měsíci

    Me wondering were did he gets an second Client

  • @TheWasian
    @TheWasian Před 2 lety +1

    Hey so are you able to combine the UI video with this one?

  • @WelshGuitarDude
    @WelshGuitarDude Před 2 lety

    Would be nice to know what this ICommand interface is all about the code is some what confusing.

  • @Lak1z
    @Lak1z Před rokem +1

    This tutorial is very great! But I'm stuck on a 21:00 part... I receive an error "There is no argument given that corresponds to the required formal parameter 'offset' of 'MemoryStream.Write(byte[], int, int)"
    Did everything as in the tutorial but still getting this message....
    It is in PacketBuilder on ChatClient
    it shows me an error on :
    _ms.Write(BitConverter.GetBytes(msgLength));
    _ms.Write(Encoding.ASCII.GetBytes(msg));
    on "Write" sentence.. Could you help me please why do I receive this error?

    • @lazar3517
      @lazar3517 Před rokem

      I have the same problem. Did you fix it?

    • @drewcumpton1232
      @drewcumpton1232 Před rokem +1

      I should have looked at this sooner, I figured it out and posted it in my comment above, but I will put it here again.
      Great Vid, very instructional. One thing I would like to add, in the Packet Builder under the Write Message module, when using VS 17.4, you have to add 1 line to it, where you actually create a buffer and get a buffer length to get it to work properly. Well, at least for me this was the case, it may be a .Net version discrepancy also since 5.0 is no longer supported any more.
      public void WriteMessage(string msg)
      {
      byte[] buff = BitConverter.GetBytes(msg.Length);
      _ms.Write(buff, 0, buff.Length);

    • @drewcumpton1232
      @drewcumpton1232 Před rokem

      @@lazar3517 See response above, hope this helps.

  • @hasanozan2393
    @hasanozan2393 Před rokem

    I have error ;
    System.Windows.Markup.XamlParseException
    "Adding a value to a collection of type 'System.Windows.Controls.ItemCollection' returned an exception.' Line number '35' and line position '18'.'
    Inner Exception
    InvalidOperationException: The operation is not valid when using ItemsSource. use ItemsControl.ItemsSource instead to access and modify items.
    Can you help please.

  • @theochasid8996
    @theochasid8996 Před 2 lety +1

    Thank you so much

  • @user-ej7zu4oy5d
    @user-ej7zu4oy5d Před 6 měsíci +1

    terrific!🥰

  • @VSLComputers
    @VSLComputers Před 2 lety +1

    How do you create a new project at all, much less a WPF app, in VS Code. I don't see these options.

    • @_buffer
      @_buffer  Před 2 lety

      Good question, you would have to use the CLI. I would highly recommend Visual Studio and not VS Code. :-)

    • @VSLComputers
      @VSLComputers Před 2 lety

      @@_buffer Ah... I thought you were using VS Code. Thanks.

  • @WelshGuitarDude
    @WelshGuitarDude Před 2 lety +3

    I get: The name "MainViewModel" does not exist in the namespace "clr-namespace:ChatClient.MVVM.ViewModel" what did i get wrong here?

    • @drewcumpton1232
      @drewcumpton1232 Před rokem +2

      I was having this issue too, I had to exit Visual Studio, and then open the project up again, and then build it.

  • @sharadranpara5449
    @sharadranpara5449 Před 2 lety

    Hi. Firstly. Thank you for the awesome tutorial. I love it!!
    I have a question. So we are doing this as a group project and when we try to connect together but we cannot chat or the server does not display the user joined. We are using different machines. Please tell me how we can solve that issue. Thanks

    • @Beste.TwitchClips
      @Beste.TwitchClips Před 2 lety +1

      you need to be in the same network and you also need to change the host address to the machine that host the application

  • @saadhasnat3730
    @saadhasnat3730 Před rokem

    I am getting many errors in "RelayCommand" class, also in chatserver on "_listener". Did anyonle else face the same problem?

    • @drewcumpton1232
      @drewcumpton1232 Před rokem

      I did at first, but found I was missing the namespaces for them, the RelayCommand class needs to have ' using System.Windows.Input; ' namespace, and then the _listener needs to have the ' using System.Net.Sockets; ' namespace. Start there, and see if it helps you progress with the program.

  • @ousspero
    @ousspero Před 2 lety +1

    Nice job

  • @GhS_Ben
    @GhS_Ben Před 2 lety +1

    Does is also work if i want to use ipv6?

  • @fai2834
    @fai2834 Před 2 lety

    I want the communication in UDP ,Is it easy to modify this to UDP?

  • @GameShorts484
    @GameShorts484 Před rokem +1

    This is not a messaging app. you can't use it without in your local network. or you can type there a regular computer ip address

    • @_buffer
      @_buffer  Před rokem +1

      You need to portforward the server and change the IP that the client connects to, it needs to connect to the server IP.

  • @renukapriyadarshani2368
    @renukapriyadarshani2368 Před 2 lety +1

    Can you please tell me how did you open both two chat interfaces at one time in 27.47

    • @_buffer
      @_buffer  Před 2 lety

      Go into the bin folder, right click the solution > open folder in file explorer, and then it's in the bin folder

    • @drewcumpton1232
      @drewcumpton1232 Před rokem

      @@_buffer Or you can right click on the ChatClient > debug > Start New Instance this will start another client

  • @kumatoons5508
    @kumatoons5508 Před 2 lety

    can you add more to that modern chat app you made 4 months ago

  • @wargalokal9760
    @wargalokal9760 Před 10 měsíci

    Cool video 🙌

  • @ascent3487
    @ascent3487 Před 2 lety

    can you teach how to make a log in page and connect the login page to the modern UI video you made

    • @user-ph9zp3fs5r
      @user-ph9zp3fs5r Před 2 lety

      two methods ahed.
      if you create another window you can do new window().show() ; and it will create another window non blocking way and then you can do this.close(); and it will shut down the current window.
      another option is to set both views as user control and bind it to content control and change it in code. change will happend after validation in code and if you ise hosting you may even inject iy as a navigation service

  • @willsouza3048
    @willsouza3048 Před 2 lety

    What is this visual studio theme and how do i set this up?

  • @enterprisemusicoffical
    @enterprisemusicoffical Před 2 lety +1

    When iam copying the code from PacketBuilder like in 27:06 it shows an error and _ms.Write is red marked please help me i tried everything

    • @kevincuppett5341
      @kevincuppett5341 Před 2 lety

      This is probably because you are using .NET Framework instead of .NET core. in .NET framework .Write() has more parameters than in Core.

    • @marslmaoo
      @marslmaoo Před 2 lety

      @@kevincuppett5341 Do you know how to fix it and if so could you please tell me?

    • @kevincuppett5341
      @kevincuppett5341 Před 2 lety

      @@marslmaoo It would involve switching from the framework to .net core. I just remade the project from scratch. I can imagine there is a way to switch though.

    • @marslmaoo
      @marslmaoo Před 2 lety

      @@kevincuppett5341 ok thanks

    • @drewcumpton1232
      @drewcumpton1232 Před rokem

      @@marslmaoo If you are using .NET 4.x framework, you can do the following:
      public void WriteMessage(string msg)
      {
      byte[] buff = BitConverter.GetBytes(msg.Length);
      _ms.Write(buff, 0, buff.Length);

  • @journalinspo
    @journalinspo Před rokem

    Can i use this code to make a chat app in winforms?

  • @ninjamateifort
    @ninjamateifort Před 2 lety +2

    nice

  • @joshfraser3991
    @joshfraser3991 Před 2 lety

    Great videos!

    • @_buffer
      @_buffer  Před 2 lety

      Thank you so much! :-)

  • @m3xpl4y
    @m3xpl4y Před 2 lety +1

    AWESOME

  • @rojetfacey5562
    @rojetfacey5562 Před 2 lety

    Hey I want some help I am currently stuck at 20mins in this video. I tried recreation this wpf but im have a problem with the WriteString function. Error code CS7036

    • @drewcumpton1232
      @drewcumpton1232 Před rokem

      Not sure if anyone replied to you, but if they haven't, this is what I found.
      If you are using .NET 4.x framework, you can do the following:
      public void WriteMessage(string msg)
      {
      byte[] buff = BitConverter.GetBytes(msg.Length);
      _ms.Write(buff, 0, buff.Length);

  • @krasus7903
    @krasus7903 Před 2 lety +1

    bro i love you

  • @exec1337
    @exec1337 Před 2 lety +3

    you god?

    • @_buffer
      @_buffer  Před 2 lety +2

      I am not :relieved:

  • @luccck100
    @luccck100 Před 3 měsíci +1

    Repository please?

    • @_buffer
      @_buffer  Před 3 měsíci

      It's available on Patreon :-)

  • @EnchikO
    @EnchikO Před 2 lety

    Hello, what happened to your multiplayer game ?

  • @TECHN0HACKER
    @TECHN0HACKER Před rokem +1

    Does this work over the internet?

  • @noyxz
    @noyxz Před 2 lety +1

    Is that only local?

    • @_buffer
      @_buffer  Před 2 lety

      No :-)

    • @noyxz
      @noyxz Před 2 lety

      @@_buffer alright thanks so much!

  • @filipkaczmarek5697
    @filipkaczmarek5697 Před rokem

    Well, i know i need to learn this because deadline is looming but i am on 15th minute and my brain starts lagging

  • @marcelosilva6250
    @marcelosilva6250 Před 2 lety +1

    source code???

    • @_buffer
      @_buffer  Před 2 lety

      On my Patreon in the description :-)

    • @user_mmm
      @user_mmm Před 2 lety

      @@_buffer but can this source code could be free?

    • @_buffer
      @_buffer  Před 2 lety

      @@user_mmm No, just like everyone else you need to get it from Patreon.

    • @user_mmm
      @user_mmm Před 2 lety

      @@_buffer wheres grid in visual studio 2022?