Instant Messaging App in C++ // Code Review

Sdílet
Vložit
  • čas přidán 30. 06. 2024
  • To try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/TheCherno. The first 200 of you will get 20% off Brilliant’s annual premium subscription!
    Patreon ► / thecherno
    Instagram ► / thecherno
    Twitter ► / thecherno
    Discord ► / discord
    Code ► github.com/TheCherno/Walnut-Chat
    Walnut ► github.com/StudioCherno/Walnut
    Hazel ► hazelengine.com
    🕹️ Play our latest game FREE (made in Hazel!) ► studiocherno.itch.io/saving-c...
    🌏 Need web hosting? ► hostinger.com/cherno
    💰 Links to stuff I use:
    ⌨ Keyboard ► geni.us/T2J7
    🐭 Mouse ► geni.us/BuY7
    💻 Monitors ► geni.us/wZFSwSK
    CHAPTERS
    0:00 - Intro
    1:06 - Building the code
    2:38 - Running all the projects
    7:18 - Project architecture
    7:52 - How I write APIs
    10:20 - Walnut-Networking API overview
    11:49 - Removing external header includes from our own headers
    17:50 - What are pointers really
    20:00 - Type forward declarations
    24:00 - Walnut::Server API and code overview
    30:03 - Walnut::Client API and code overview
    30:57 - Network utility functions
    32:44 - Client connection status
    This video is sponsored by Brilliant.

Komentáře • 101

  • @TheCherno
    @TheCherno  Před 11 měsíci +13

    Thanks for watching, hope you enjoyed! ❤ Let me know if you want to see more Walnut Code Reviews!
    You can try everything Brilliant has to offer-free-for a full 30 days! Visit brilliant.org/TheCherno - the first 200 of you will get 20% off Brilliant’s annual premium subscription!

    • @obinator9065
      @obinator9065 Před 11 měsíci

      how you doin bro

    • @clintonreisig
      @clintonreisig Před 11 měsíci

      Security? Privacy?

    • @harshsulakhe2720
      @harshsulakhe2720 Před 15 dny

      Hey when I double click on .bat file , I am not getting anything installed
      Error : system cannot find the path specified

  • @szirsp
    @szirsp Před 11 měsíci +11

    17:25 (TCP, UDP) ports are limited to 16 bit, not sockets.
    A socket is just a descriptor to identify an endpoint for communication. It can be a combination of domain, (IP) address and port number.
    So in theory you could need 48 bit for TCP/IPv4 and 144 bit for IPv6. And that's just for one domain+type (TCP = SOCK_STREAM). You add UDP and non IP connections like Unix sockets, IPX...
    But there is an OS limit (10k ..10 million) (max open files on Linux for example) ...
    ...uint32 will probably be fine for a while (unless you are using a supercomputer as a port scanner ;)

  • @user-th5tc5db3d
    @user-th5tc5db3d Před 10 měsíci +16

    Hey, Yan. I really appreciate what you do, but there's a thing I want to mention
    I understand that you want your videos to be pretty short. I also understand that you're a type of programmer who wants to get a deep understanding of things and propagate that knowledge to the audience. But when I clicked at this video, I expected to see you explaining the architecture of your chat app. But what I saw instead was you talking about pointers, headers and forward declaration. For my opinion it'd be better if you moved this kind of stuff into your c++ playlist and talked about the thing that's in the title of the video. Thank you!

  • @user-fj7cg1qn2r
    @user-fj7cg1qn2r Před 11 měsíci +3

    These videos are really useful for learning c++ thanks for this!

  • @dany4977
    @dany4977 Před 11 měsíci +2

    Beautiful! thank you for your consistent effort in making your work clean

  • @fishinker
    @fishinker Před 11 měsíci +2

    Would love to see the rest of the code review!

  • @midnqp
    @midnqp Před 11 měsíci +2

    Congratulations 🎉 on your 800th video on CZcams ✨

  • @that404nerd
    @that404nerd Před 11 měsíci +1

    Hopefully you will make videos about file i/o ! Great video btw

  • @mingm
    @mingm Před 11 měsíci +3

    im interested in how does the network thread push the received messages to the UI thread safely. multithreading feels so hard

  • @mattshu
    @mattshu Před 11 měsíci +1

    I'm sure you've mentioned this before but can you tell us which font you use for these programming videos? Love this theme and everything!

  • @aname9806
    @aname9806 Před 11 měsíci +3

    Holiday in Germany as well, Servus!

  • @Sultan___
    @Sultan___ Před 11 měsíci +15

    cherno is the best !!11!!!1!!

  • @gstreetgames2530
    @gstreetgames2530 Před 11 měsíci +5

    Any chance you would ever make a video about contributing to an open source privacy project like Session, Element, or for C++ Hush?

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

    I would love to see a server dev series specifically tailored towards game dev. Particularly with subjects like how to efficiently validate collision detection and raycasting from the server side without the availability of a gpu.

    • @ltstaffel5323
      @ltstaffel5323 Před 10 měsíci +1

      Collision detection would be the same on the server as on a client/singleplayer game except that when a collision happens (like the player running into a wall) the server would simply disregard any further attempts to walk forwards. Usually servers store the location of every player and when a player presses W it sends a message to the server saying the player wants to move forward. From there the server does collision detection and updates the player's position then sends back the position to the client. This is a little bit of a naive implementation in some ways but that's the idea.
      Raycasting would not be done server-side because that's purely visual, and servers don't do anything visual if they're well-made. It'd be up to the client to receive a list of the objects in sight of the player from the server and then the client would render and raycast itself.

  • @sk4d3
    @sk4d3 Před 11 měsíci +2

    Remembering to correct types on Lib update seems a bit tedious (17:32). I think it could be useful to use static_assert(sizeof(HSteamNetPollGroup )==sizeof(uint32_t)) at the cpp top to check type sizes so it would give a more visible hint (also abstract all HSteamNetPollGroup in hpp with typedef instead of uint32_t to make it easier to update). As the Compiler would simply cast instead of throw an error, no?

    • @JohnSmith-hi5vy
      @JohnSmith-hi5vy Před 11 měsíci +3

      Also, it would be even better to use type_traits to check types at compile time. Here's how it would look like:
      #include
      static_assert(std::is_same::value, "Type mismatch");
      This is much better, as it handles this case:
      static_assert(sizeof(float) == sizeof(int), "fail"); // fine
      This option will pass, but this one won't:
      static_assert(std::is_same::value, "Type mismatch"); // error

  • @tomaskot9278
    @tomaskot9278 Před 11 měsíci +8

    Just a small note - there is an alternative way how to forward declare a class that in my opinion in cases like this is more clear and adds less noise to the code. You don't have to say "class ISteamNetworkingSockets;" somewhere at the top of the code, you can just simply add the word "class" in front of the type directly at the place where it is used, so "class ISteamNetworkingSockets* m_Interface = nullptr;"

    • @and_then_I_whispered
      @and_then_I_whispered Před 11 měsíci +4

      The forward declaration is better, because the word class in front is a C-style thing I guess and most people don't know about it, which I didn't know either until you mentioned 😂.

    • @ahmadalastal5303
      @ahmadalastal5303 Před 11 měsíci +1

      One side note here is that you can't use the forward declared variable before you declare it in the code, that is why I prefer to do it at the top of the file, but sometimes I use it exactly as you said for exactly the same reason you mentioned

    • @user-dh8oi2mk4f
      @user-dh8oi2mk4f Před 11 měsíci

      I prefer the forward declaration at the top of the code, but to each their own.

    • @nepp9574
      @nepp9574 Před 11 měsíci +1

      Makes it more confusing imo. If you use it twice, then one gets it and the other one doesn’t. If you remove one of them, all of a sudden your code stops working. It feels like including header files halfway your code, makes no sense to me.
      It’s possible but I really don’t see the point.

    • @tomaskot9278
      @tomaskot9278 Před 11 měsíci +1

      @@and_then_I_whispered And that's why I wrote the comment, because it is not so widely known (and thus? not so widely used).

  • @cnb_kevin
    @cnb_kevin Před 11 měsíci

    Autofocus on the camera was a bit distracting.
    These networking videos are good to have for the future. I do have future game projects that will require Not-Hazel(that's not the name, but it draws some inspiration from Hazel) to support networking. It would be interesting to see how one should handle timeout (let's say a client does not exit gracefully) or if GNS has something for that already.

  • @simplegamer6660
    @simplegamer6660 Před 11 měsíci +7

    Why batch/shell scripts? Why lua scripts? Why not to use CMake? CMake + vcpkg workflow is an absolute fire, try it out. All you might need for this is to set a few environment variables besides installing the mentioned apps, and boom, now your C++ has a package manager, like every modern language! No more need in manual copying of dlls, libs and headers, no more booooring project set-up stage where you adding all your dependencies in your VS project settings!

    • @TheCherno
      @TheCherno  Před 11 měsíci +7

      I’ve tried it out, I hate it

    • @simplegamer6660
      @simplegamer6660 Před 11 měsíci +1

      @@TheCherno Why so?

    • @dave7244
      @dave7244 Před 11 měsíci +2

      @@simplegamer6660 I use CMake on my own projects and quite frankly it can be a PITA.
      Build systems in general are pretty crap. At least it isn't JavaScript.

    • @simplegamer6660
      @simplegamer6660 Před 11 měsíci

      @@dave7244 I wanna ask, if you're using bare cmake, or in conjunction with the vcpkg, because it's like two different worlds: in the first case I'm gonna agree with you, and in the second case I'm curious, because it's working perfectly for me.

    • @dave7244
      @dave7244 Před 11 měsíci

      @@simplegamer6660 I am relatively new to C++, but I am not new to software development. I dunno what vcpkg is or does, but just looking quickly at the homepage it looks like a dependency manager. I also try to stay away from anything that is built by Microsoft these days. I've tried Conan and it gave me more problems than it really solved. I personally am fed up of dependency managers.
      I normally either using FetchContent_Declare and the use or just vendor the repo itself as a git submodule and then just tell CMake where to look. It works for that I am doing at the moment.
      The longer I work in Software Development. The less "clever" I want. I personally might just go back to using Makefiles (I use them with Go/Python already).

  • @SETHthegodofchaos
    @SETHthegodofchaos Před 11 měsíci

    Are we going to look into netcode aka client side prediction and server side rewind?

  • @jackpioneer3566
    @jackpioneer3566 Před 11 měsíci

    Is it save to execute callbacks in a different thread? I always use thread-safe queues to store the messages for my main thread and poll them on tick 🤔

  • @nordicus666
    @nordicus666 Před 11 měsíci +3

    watched first 6 minutes and got a question: how did you solve the problem of receiving message mid-typing your own message in console clients? won't it get split and ruin all visuals? when i was trying to create similar apps in the past - i haven't found a workaround

    • @contentprogramming
      @contentprogramming Před 11 měsíci +3

      not 100% sure but , i think you can get full access/control on the console text buffer ,
      so if a new message is received you can take a copy of the typing text ,
      then put the received text in that line ,
      then put back that copy of typing to the next new line
      🤔🤔

  • @herrdingenz6295
    @herrdingenz6295 Před 11 měsíci +3

    hello from germany..hope you have fun here :D

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

    Hey Cherno, could you do a crypto or stock screener GUI in C++. That would be a cool portfolio project for quant developers

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

    What color theme is he using in Visual Studio? I thought it was gruvbox but it seems different though

  • @user-we6cc7lx6i
    @user-we6cc7lx6i Před 11 měsíci

    Before start the video, I want to read the source code and where to get it?

  • @desperateee
    @desperateee Před 11 měsíci +1

    what theme is he using

  • @aftostok6080
    @aftostok6080 Před 11 měsíci +2

    Networking is cool , Can you make a video on how to deploy this server?

    • @nepp9574
      @nepp9574 Před 11 měsíci +1

      It is in the previous video.

  • @y4ni608
    @y4ni608 Před 11 měsíci

    Man i hoped so much he would review my game engine when i saw the "Code Review" in the title

  • @koftabalady
    @koftabalady Před 11 měsíci

    Hi, Cherno. when my friend tries to connect to my chat app in Java, it doesn't work or connect him although I gave him my public IP and port. what am I doing wrong?

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

      if your friend is not at your house then the issue is most likely port forwarding, which is a setting you need to configure on your home router for the port that your app uses.

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

      Wow, thanks for replying after all of this time. I forgot I made this comment. but I have read a book about networking and figured the problem out, it was about DMZ. anyways, I appreciate your help even after all of this time...@@ltstaffel5323

  • @martinprochazka3714
    @martinprochazka3714 Před 10 měsíci +1

    Actually if you mix up class/struct in forward declaration, g++ won't give a crap and clang will give you a warning that MSVC *doesn't like that* 😂 What's the actual issue with MSVC I have no idea as I don't do Windows. But if someone cares to elaborate you're more than welcome 🙂

  • @dingoDogMan
    @dingoDogMan Před 11 měsíci

    Hey guys hey great is coffee!! zoom in zoom in coffee is great isnt it?

  • @JohnSmith-ze7sv
    @JohnSmith-ze7sv Před 11 měsíci +2

    Hey Cherno. Question :
    I'm a dev comming from C#
    Why do Cpp developers have their own custom typedefs for primative types?
    If i want an unsigned interger for example - I will simply type 'unsigned int' as opposed to defining a type 'uint32'
    I know we want all this shorthand for convenience.
    But if it isn't in the standard library, or as part of the actual language itself - why bother? We just end up with a hundred custom ways of defining the same basic types over and over again.
    For example you have a typedef of 'ClientID' which is essentially a uint32_t. Why not just leave it there? A ClientID is a uint32.... No need to have it defined as its own type.
    My main gripe is that In order to find out what data I am passing into an interface I have to look in through all of those typedefs to find out "Oh - it's just an int"

    • @nbhjbhyvgbhyuvbhuynnjbhu
      @nbhjbhyvgbhyuvbhuynnjbhu Před 11 měsíci +4

      The primitive types can be different sizes on other platforms. A long is 32 bits on Windows and 64 bits on Linux. If you have to use something like ClientID, it's for semantics but you will always set it with the API that defined it.

    • @theEndermanMGS
      @theEndermanMGS Před 11 měsíci +2

      There are a bunch of possible reasons. Semantic type naming (ex: size_t vs unsigned int for indices), making porting easier when you need type sizes to remain consistent across platforms with different primitive sizes, making templates easier to work with (ex: containers all have iterator aliases for convenience), making it easier to change the underlying type if necessary, and so on.

    • @v01d_r34l1ty
      @v01d_r34l1ty Před 11 měsíci +1

      The above 2 comments mention the primary reason for it: cross-platform compatibility. 2 additional reasons could be: generalized specifications (not tailored to any specific language) and variable acquisition / usage association.
      For example 1: OpenGL is a specification, who's to say it has to be implemented in C/C++ instead of say Rust?
      For example 2: Say you have a couple methods, generateID(uint32_t id) and bindID(uint32_t id). It's pretty obvious how it's used, but who's to say you can't just make up your own ID and try to bind it? Does generateID just kick back a random number or does it have to register something? Not to mention header files do not have to include variable names (relevant to IntelliSense). Instead, having a ClientID type makes it more clear that you have to somehow acquire this specific ClientID instead of just giving a random number. Documentation and comments aren't everything. Code should be self-explaining and this can be a way of doing just that.

  • @bradfry2259
    @bradfry2259 Před 11 měsíci

    I wish I knew what any of this meant, not even sure why I am watching this but it's interesting.

  • @badassopenpolling
    @badassopenpolling Před 11 měsíci +1

    Hey Cherno - Can you enlighten us with Matching Engineer in C++ which covers Networking, Multithreading and design architectures
    In my opinios - It would be nice hands on which covers wide variety of C++ with real time problem.

  • @skypuff
    @skypuff Před 11 měsíci

    This dude is a genius,

  • @ouardito
    @ouardito Před 11 měsíci

    Cpp is fun

  • @x-root3017
    @x-root3017 Před 11 měsíci

    Please sir may you make a course about git and github 😁👍

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

    I am assigned to write exe code, that communicates with web code on server, My task is to call its API or URL to send some data and on the other hand server can request data from me. What are all possible ways to do this bidirectional communication?

  • @ipizza9941
    @ipizza9941 Před 11 měsíci +1

    This is way to high level for me to understand. Can someone maybe recommend a bit more beginner friendly networking tutorial in c++.

  • @ipizza9941
    @ipizza9941 Před 11 měsíci +1

    Did he just say making an instant messaging app is the hello world of networking?

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

    Please sir,i need help
    I want to learn OpenGL and i need to link the glfw and glut libraries in order to continue but i am using vsCode and i tried lot's of things on the internet but nth worked.
    Please can you help me ?

  • @MrCubo2009
    @MrCubo2009 Před 11 měsíci +1

    Hey Cherno, I CHALLENGE you to make a programming language in C++, it is an interesting project, could you accept?

  • @osamaalbanna2200
    @osamaalbanna2200 Před 11 měsíci +1

    What are your thoughts about Rust?

    • @anon_y_mousse
      @anon_y_mousse Před 11 měsíci

      If he's like every other intelligent person then he'll think it's garbage.

  • @acidrazor
    @acidrazor Před 11 měsíci +1

    Geezas christ, I heard "pedo file" several times and were wondering wtf they were and how this sounded..... then I realized he was saying header files. Thank goodness

  • @Jkauppa
    @Jkauppa Před 11 měsíci +1

    sauce code

    • @Jkauppa
      @Jkauppa Před 11 měsíci

      vs studio makes the code management harder, gcc is better by hand

    • @Jkauppa
      @Jkauppa Před 11 měsíci

      C is lien

    • @Jkauppa
      @Jkauppa Před 11 měsíci

      if something is complex, ie too hard, its confusing dev, not helping it, at all

    • @Jkauppa
      @Jkauppa Před 11 měsíci

      and reason "you need to do this" is nonsense always

    • @Jkauppa
      @Jkauppa Před 11 měsíci

      whomever do it yourself lmao, yep the work and leave fearing others out

  • @teksatan4699
    @teksatan4699 Před 11 měsíci +1

    Hm wonder why my comment got deleted. Odd.

    • @KarabauPlay
      @KarabauPlay Před 11 měsíci +2

      Communist youtube

    • @theEndermanMGS
      @theEndermanMGS Před 11 měsíci

      @@KarabauPlaySo a privately-owned company doing capitalism at a massive scale is apparently communist for exercising control over its private property. Make it make sense.

  • @craigkinney853
    @craigkinney853 Před 11 měsíci

    Slooooow dooooown.

  • @lark-6381
    @lark-6381 Před 10 měsíci

    why do you looks like mr beast💀