Thanks for watching! Links to everything in the description, give Walnut Chat a go (if the server hasn’t crashed yet…)! Also don’t forget to check out Hostinger for all your server and hosting needs - go to hostinger.com/cherno and use coupon code CHERNO at checkout! ❤
@TheCherno, With all due respect and time constraints and all. I feel slightly disappointed that you had to use a 3rd party to construct your networking protocols. You can easily go from Linux to Windows by creating a client and server program and vice versa with using winsocks2 for windows and cygwin network drivers to run native Linux apps on windows. I feel only a handful of us who are insane & hardcore enough to write our own game & physics engines from scratch should also have this same belief in networking as well. Just my 2 cents =)
@@CodeParticles Why? How is what you're doing any better than using a 3rd party that handles the OS specifics for you? If anything, your solution would probably result in less efficient code, because you're reinventing the wheel. And, if it is truly about the idea of being "insane and hardcore", as you put forth, then why use cygwin network drivers? (That sentence doesn't make that much sense btw, but I'm interpreting it as you're using it as a method of portability between Linux and Windows). Wouldn't a truly "insane and hardcore" thing be to simply build your own network layer that creates an abstracted socket implementation built on top of each individual OS API you wish to support? He mentioned that he doesn't have a lot of experience in networking, and his channel caters to game developers - I would argue his choice of using the steam library is actually a very good one. It's generally not advisable to teach the intricacies of a subject you are not intimately familiar with, and a 3rd party library allows him to cover "how to do it" without really understanding how it works.
@TheCherno hey great video again. I have learned more about C++ from your tutorials than any other ones. Just a suggestion would mind creating a video on C++ Software interview prep? I'm sure a lot of people would be interested. Thank you.
Side note, I don't think you need crossover cables anymore. I think NIC's can auto negotiate direct connections now. Some kind of update to the Ethernet Standard.
I love this channel for actually going balls deep into these kinda topics. A typical internet article would leave me with questions and abstract explanations without allowing me to actually write some decent code.
Yesss please more Linux videos! I'm especially interested in how to make proper cross-platform software, that is easy to build on both Linux and Windows.
That's pretty easy conceptually :) I write c++ code on windows that compiles for linux and windows. I am at the network level so a ton of my code is low level and OS dependent. All you do is make a platform specific layer at the very base where you wrap all platform specific code under the same functions. Then you just configure your compilation params to only compile the files for the target platform. You can do this via cmake config params, in visual studio you can make different build targets. etc. An example is this: Windows_Platform.h int platformIndependentCode() { do something windows specific; return value; } Linux_Platform.h int platformIndependentCode() { do something linux specific; return value; } main.cpp int main() { platformIndependentCode(); return 0; } then compiling for linux would be: g++ main.cpp Linux_Platform.h this clearly wouldn't work and is a loose example, but that's how most do it. They wrap it all up in the same function redefined for each system. You can do the same thing using defines. Something like this: Platform_Secific.h #ifdef WINDOWS int platformIndependentCode() { do something windows specific; return value; } #else ifdef LINUX int platformIndependentCode() { do something linux specific; return value; } #endif for this method, you can define one or the other. Obviously this needs cleaned up because you could end up defining both and blah blah blah errors errors bugs right? But you get the basic idea I hope. Let me know if you have questions!
I'm solutions architect, and software engineer in field of networking for around quarter of century and I'm surprised how developers lacks in networking programming knowledge in 21st century, where we live in connected world since decades. I saw such deficiencies even among programmers who were developing 5G. Anyway you're doing excellent job making your videos! Good luck and please keep going. It's a pleasure to watch your videos.
I recently graduated with my bachelors in Computer Science. At my school they did not cover it well. There was very little programming. We mostly learned about the OSI Layers and protocols. Which I think is valuable and it is worth knowing, but we certainly did not learn what we needed to learn to be good engineers. Luckily great resources like Cherno exist- so here I am! TL;DR: I believe you. I do not think my CS education covered networking very well.
You're right, Marcin. Meanwhile, could you please suggest a learning path (preferably with a few online tutorials) that traverses from fundamentals to expert level knowledge?
@@joshnjoshgaming Ok, here we go. It seems like you're a fanboy. Let me break it down: 1. Fuck Nvidia. With that out of the way 2. No major engine support. Although, I don't use engine and go low level most of the time, there are times where I use an engine for quick implementations. 3. No debugger. "Oh but that's an IDE thing". No. Linux just particularly sucks at providing an IDE. I use Emacs, even on Windows but I still use Visual Studio for its debugger and LSP. There's nothing like it in the market. No. Jetbrains doesn't come close 4. Collaboration. You know, when you have a job, you don't work on your own. Developers work with you. To make the best of your time, remove the OS barrier. 5. Why would I bother about Windows? Because everyone plays games on Windows so why would I develop on some platform and fix errors on something else? One tool doesn't fit all. I've been a hardcore linux user for like 5 years. Loved it. But the support isn't there.
@@friedrichmyers i asked a simple question, douche, way to make assumptions and be rude for no reason. also, its clear you go "low level" (xD) cuz I don't know what engines arent supported, unreal godot and unity all have full linux support.
I use c++ builder, and they usually bundle a networking library called Indy v10. It really has a lot of client and server networking components with support for SSL. You can do very low level programming for both tcp clients and servers, or add your own web server. I have actually use this to create an email client to aid in automating some email tasks via command line .
awesome video. I'm not sure if you were aware, but Visual Studio has a remote debugging feature. You can edit on Windows, and compile and debug on another machine via ssh. This would save you the trouble of copying the code, compiling the code figuring out how to debug in linux (in case something doesn't work). Hope this helps in the future.
About the executable not finding the shared library when you execute it, you could either: 1. set the LD_LIBRARY_PATH to point to where your executable is ( export LD_LIBRARY_PATH=/path/to/shared/lib:$LD_LIBRARY_PATH ). This way the dynamic linker will find the library. 2. ELF files have an entry called rpath. This is used by the dynamic linker to load the shared libraries. When you link the executable with the shared library, you can tell the linker to set rpath to '$ORIGIN' to load libraries in the same directory as the executable. Tbh I have no idea why 2 is not the default :P
FYI: There is 2 RJ45 termination standard: 568A and 568B. A straight Ethernet cable is a cable that has both ends terminated with 568A or 568B. A crossover cable has one end terminated 568A and the other one is 568B. There is no 568B crossover: it's a 568A. Hooking 2 PCs back-to-back (i.e. without a switch in between) with an Ethernet cable no longer required a crossover cable IF both interface card are set to 1Gbit or higher. The network cards will do the crossover "internally". It's in the specs of Gigabit network. 10Mbit and 100Mbits connections do require crossover cables even if the card is capable of Gigabit. The same goes when connecting 2 switches (or hubs) using regular network ports.
I think the "TV show" aspect is good, its a lot more fun to watch and it doesn't take any information away from the video. In fact I think its a better learning experience as a whole
@@sirsneakybeaky Honestly it helps to be compelled into using lower level functions to provide a service. You learn a lot more about the system under the hood and are more able to anticipate problems or possible complications later on. I made a webserver in C before and I learned a metric ton about networking that I wouldn't be able to had I not ventured out of my comfort zone. (The entire outside world of which happens to be anything that has to do with networks haha)
I use asio. It is very good and yes, I won't touch anything that requires boost either, but as you note asio has a stand alone project and that's what I use.
Thanks so much for making this video. I am new to C++ and bought some Udemy courses. I was surprised when going through them that I did not see lessons on Networking.
I remember writing a c# networking system based on tom weiland's original c# networking tutorials and realizing later how much a waste of time it was to write it because the end result ifor all these libraries is the same: send message, send message reliably over udp, receive message. Everything else, you should be doing at the application level anyways so it doesn't make sense to write the actual sockets library unless you're curious to understand it, or if you think you have some ground breaking ideas that will revolutionize how the underlying transport works. So I agree, many times you don't need to understand how something works as long as you can effectively use it, better to concentrate on your own application.
You don't want to just "reliably send mover udp" though. Sometimes you need reliability and ordering, sometime you just need reliability without necessarily ordering, but most of the time for any real-time application like a game, what you want the most is just the latest one reliably, not caring about lost messages when a newer have been sent. Then, there are various strategies to archieve that to various trade-off of latency and bandwidth, depending on your bandwidth needs. (the most efficient trick for low-latency game networking is a lot of redundancy, because you want the lowest latency possible and the bandwidth usage is usually pretty minimal).
@@Kazyek i understand that, i do that at the application level using a tick system, each packet is associated with a tick and I can decide how to handle out of order packets. My point was you can find libraries thay implement the low level transports already and writing them yourself is usually a waste of time unless you have some particular requirements on how the messaging works.
@@phee3D Your point is wrong though. That particular requirement of wanting a mix of reliable communication and minimum-latency communication comes up in any fast action game. I would say though, there could easily be a networking library specific for games that could expose the right interface, I haven't investigated that. It's also really simple to develop, it's barely an afterthought compared to how you actually architect a game when networked: everything needs to eventually be unified on an event stream regardless if caused by network, user input, game script, response to detected events, "ai" input, etc. then you have to build the game logic underneath that layer. That's without considering the tick rates of concurrent threads, or if you're lock stepped, what your interpolation/extrapolation method is, how the actual architecture works (p2p, single server, or more like an mmo), if the server has complete authority over all actions or if there is some client event triggering with heuristic checks, or so many other strategies. Writing some boiler plate standard code to move bytes is not an issue or difficulty whatsoever.
@@Bozebo you didn't understand what I said. I never said you don't need a mix of reliable communication as well as fastest possible communication. I said these libraries should perform the following functions: send message, send reliable message over udp, receive message. By "send message", the first one in this list, I meant just sending messages as fast as possible, without considering any reliability. I myself am currently making a game where I use unreliable message sending for things such as player position and I also use reliable messages for events such as player death.
Just wanted to say I've just discovered you're channel, and this is such fantastic content. Really appreciate the hard work you put into these videos, I look forward to following you!
c++ is powerfull languge when it comes to performonce i remember when i built a webserver using c++ i has so much fun learing how the socket works and serving full static website , great video btw
@@vivekkoul4428it's very different because javascript is a super high level language, and nodejs abstracts everything away. if you want to learn more about how computers actually work, you should play around with C and C++ for sure
I would love to learn more about networking basics so I can understand what the high level process is for making a connection to a server, how to handle basic errors, etc.
Great Stuff, I love these type of videos where you teach more on things that are not really apart of c++ and where you need outside libraries, and learning those are exetremly confusing e.g learning encryption in c++ took ages and only installing the libraries where a whole process in it of itself
Every CPP dev: "I didn't like all the existing solutions because I didn't want to rely on third party libraries, so I made my own which can can download in the description to rely on in your own code" 😂
I Love C++, it's my favourite programming language. C is also cool. But I love the syntax of C++, I love how it works on basically everything, I love how you can access it from other languages like C#. I also love the performance. Who's with me? :D
26:30 you for sure want your executables to be _owned_ by root:root though, so an unprivileged user can't change them. Generally a "good enough" pattern is to have files chowned to root:root, a nologin user called something like "app-server-headless" that runs your program(s) (usually under systemd nowadays), and then some accounts for your server administrators that have sudo access. You can restrict the sudo access or start messing with groups or even SELinux if you want to go hard on hardening, but "good enough" works aight.
There will be Networking in the C++26 standard most likely. You can search for Networking TS. And the library that is closest to that and will give you the easiest time migrating would be asio. There is a standalone version of asio you can get from ThinkAsync also, no need for the entire boost library. Honestly I think even for Games asio is a really good fit. But as you said: everyone has their preferences for sure and you are not forced to use that at all also. Yours seems to be going against the mainstream a little bit. That also shows in your build system choice :p
I searched for Networking TS and it seems that no one is currently working making the changes necessary to get it into C++26. Is It still being worked on?
Honestly I've never had any issue with cpp not having a socket interface. I use cpp all the time at work for windows based applications. When I use it at home, it's always for something OS specific. There aren't many projects where I would choose cpp as the go to language if it needed to be OS agnostic. Obviously it makes sense for a game engine, but I don't build game engines :)
I looked through the comments and could only find like two people addressing this point, so I'll address it myself and add to it, that you should've just used LD_LIBRARY_PATH and set it before calling the program. The path can be relative as well, so subdirectories are fine, but you can even just use '.' in cases where they're in the same directory. Second of all, if the distro you're using is setup properly then you should be using and already have a path for /usr/local/lib or in some cases /usr/local/lib64, though most would only have that if you do any 32-bit cross compiling work. You almost got that one right, but it was backwards because the local comes first. It's where all of the files should be collected that you create on top of the distro files.
Networking is so fun, You should also try and make your own integrated networking api. Non-blocking sockets using select or epoll is sooooo fun and gives you so much control. They aren't large APIs honestly.. you can implement a simple non-blocking TCP client/server handler with select or epoll in under 200 lines of code. This would be my honest recommendation for any TCP related networking you need. Though it would work just as well if not better for UDP, and your game engine's overall workflow. I can even see easy integration into your event system.
I feel like the next iteration of C++ should have a standard networking implementation. Even just an open/listen/close/connect. and thats it, would actually be enough. its actually pretty stupid it doesnt already, should have been in starting at 17 at the latest.
If you're watching for pure enjoyment that is perfectly fine, but just make sure you don't get overwhelmed. There are many years between a new programmer and all of the advanced topics he covers in his videos. Definitely cool to see the "endgame" but make sure you focus on the basics as well! Good luck with the journey :)
ASIO is the better part of boost. And it is independent of boost actually and you can have a standalone installation. For a rigorous use of any I/O (not just networking) what I came to understand over 3-4 years is that you absolutely need to have a reactor or proactor design in palce anyway (maybe also with an event loop). That's exactly what ASIO is. Nothing more, nothing less. That's why I even use it on my embedded projects (esp32 with only 512 kb of ram has ported ASIO). It just makes I/O in general more robust and failsafe. The very concept of I/O is very complicated. These designs not only make life easier, they will at the same time help you understand the true nature of the problem and how to solve it.
By the way, about networking peer to peer with Windows for gaming, I was able to do that with a Vista machine back in the day. I was at a friend who didn't have a router (oh, the 2000s), and so I literally just plugged an ethernet cable between our notebooks and used an ad-hoc network option in the Windows network manager. It was surprisingly straightforward, like 1 minute and 10 clicks once I knew where to go. Edit: fairly sure that was also possible over wifi, you could self host a LAN wifi on your notebook, and have other notebooks join, it's been a while since I messed with that though so I don't recall for sure.
I was so happy to see a networking in c++ video, since all the videos I've seen try go into boost::asio just to abstract it away with some custom wrapper class. I never heard of steam's networking library. Please do more Linux videos as well!
Sorry but you're wrong here. "A headless computer is a computer system or device that has been configured to operate without a monitor, keyboard, and mouse. A headless system is typically controlled over a network connection, although some headless system devices require a serial connection to be made over RS-232 for administration of the device." - Wikipedia The fact that it reads from stdin and writes to stdout makes it possible to redirect it's input/output and disown the process to make it run in the background. One could even run it in `screen` and then detach from it. In all instances, this is a headless application, it does not require a head (monitor) to operate.
@@gnif Yes, exactly, and that was sort of what I was trying to hint at. If you break out of or disconnect from the CUI shown, I suspect the server process also stops along with it... Most traditional Unix commands can also be run in a headless way by means such as you mentioned, or via nohup for instance, so I think it would be a bit of a stretch to call every cmd line tool a "headless configuration" just because of that.
@@benhetland576 Yep, headless means the person operating the computer it's running on doesn't see an interface. So most server programs are, as long as they don't have a TUI or a CUI, and obviously definitely no GUI.
@@anon_y_mousse Isn't TUI just a travel agency? ;-) IIRC we used to call them CLI (command line interface), but nowadays it's too easy to confuse it with the CLR/CLI used with C# (and Active X)... Of course, one might just want to avoid a Terrible User Interface completely 😁 Oh.. and for example Virtual Box can run an entire OS with a GUI in a headless manner too!
@@benhetland576 Back in my Yahoo Chat days we always referred to it as a CUI, but these days I see TUI a lot more because xterm and gnome-terminal are the most common terminal emulators used. I'm good either way, but since people can't seem to agree on terminology I figured I'd cover the bases. As to Virtual Box, yeah, all that's required for it to be headless is no direct user interface.
You should have a look at Holepunching using udp to establish a Peer To Peer connection, basically a connection between two equal machines without a server (Server Less) ...
This isn’t what they call server-less, also you still have to port forward traffic from the peers router to the peers or a 3rd party machine to act as a server for hole punching and it can’t be a chat of more than two attendees
@@CR33D404 it definitely can be a chat for more than two( look at bit torrents) also there is no port forwarding required for hole punching (since that is the entire point of it)
@@CR33D404 Depends on the router configuration. For wireless internet/cell though assume nothing's going to work, you have to use a relay server even for P2P actual hosting (fallback for if can't matchmake a decent host who is not on wireless), as you cannot hole punch!
@@schrottiyhd6776 but it still need a 3rd party machine to bypass the need of port forwarding or the limitation of CGNAT and to distribute packets to other machines, I’m i missing smth?
You shouldn't need the `protobuf-compiler` package for running a binary. The compiler is the part that takes in a `.proto` file and generates code in C++ or another language for serialising/deserialising the protocol. For running your binary you should only need one of the `libprotobuf` packages (in this case it looks like `libprotobuf23` was installed as a dependency of `protobuf-compiler`, and that would give you the `libprotobuf.so.23` shared library that you needed).
There's no networking in C++ because protocols like TCP and UDP, etc. are only about 40 years old which means they're not considered mature enough for the C++ standard.
There was a strong push on the committee to add networking to the standard. In the end it's quite some effort to get it to the level of maturity C++ guarantees, and members choose features that are better suited for their skillset. ^^ but if you want to do it nobody is holding you back.
I love Cherno's videos for many reasons, his preference for GUI and Windows is absolutely 2 of them. I have lost count of how many times I edited a file in Windows and uploaded it to the server just to avoid having to edit it on the server CL. lol
Thanks for watching! Links to everything in the description, give Walnut Chat a go (if the server hasn’t crashed yet…)!
Also don’t forget to check out Hostinger for all your server and hosting needs - go to hostinger.com/cherno and use coupon code CHERNO at checkout! ❤
Hell yeah! This is awesome!
@TheCherno, With all due respect and time constraints and all. I feel slightly disappointed that you had to use a 3rd party to construct your networking protocols. You can easily go from Linux to Windows by creating a client and server program and vice versa with using winsocks2 for windows and cygwin network drivers to run native Linux apps on windows. I feel only a handful of us who are insane & hardcore enough to write our own game & physics engines from scratch should also have this same belief in networking as well. Just my 2 cents =)
@@CodeParticles Why? How is what you're doing any better than using a 3rd party that handles the OS specifics for you? If anything, your solution would probably result in less efficient code, because you're reinventing the wheel. And, if it is truly about the idea of being "insane and hardcore", as you put forth, then why use cygwin network drivers? (That sentence doesn't make that much sense btw, but I'm interpreting it as you're using it as a method of portability between Linux and Windows). Wouldn't a truly "insane and hardcore" thing be to simply build your own network layer that creates an abstracted socket implementation built on top of each individual OS API you wish to support? He mentioned that he doesn't have a lot of experience in networking, and his channel caters to game developers - I would argue his choice of using the steam library is actually a very good one. It's generally not advisable to teach the intricacies of a subject you are not intimately familiar with, and a 3rd party library allows him to cover "how to do it" without really understanding how it works.
@TheCherno is possible to create raw sockets in c++ windows ?
@TheCherno hey great video again. I have learned more about C++ from your tutorials than any other ones.
Just a suggestion would mind creating a video on C++ Software interview prep? I'm sure a lot of people would be interested. Thank you.
I think that the lack of networking built-in in C++ is a deep joke about C++ programmers finding making friends difficult :)
In C++ your friends can touch your private parts
@@notuxnobux 💀⚰
@@notuxnobux lmfao
Type enemy instead
Java devs dying at this joke
Side note, I don't think you need crossover cables anymore. I think NIC's can auto negotiate direct connections now. Some kind of update to the Ethernet Standard.
since gigabit it's mandatory. Some 100 NICs also support it as a bonus
I think the standard was MDI or MDI-X or whatever - but yes.
I can confirm modern computers don't require crossover cables to communicate when connected directly to each other. I used rtp midi just fine
Ah cool. I’m still living in the 2000s 😆
@@kurt7020 yup Auto-MDIX.
I love this channel for actually going balls deep into these kinda topics. A typical internet article would leave me with questions and abstract explanations without allowing me to actually write some decent code.
Yesss please more Linux videos! I'm especially interested in how to make proper cross-platform software, that is easy to build on both Linux and Windows.
That's pretty easy conceptually :) I write c++ code on windows that compiles for linux and windows. I am at the network level so a ton of my code is low level and OS dependent. All you do is make a platform specific layer at the very base where you wrap all platform specific code under the same functions. Then you just configure your compilation params to only compile the files for the target platform. You can do this via cmake config params, in visual studio you can make different build targets. etc.
An example is this:
Windows_Platform.h
int platformIndependentCode() {
do something windows specific;
return value;
}
Linux_Platform.h
int platformIndependentCode() {
do something linux specific;
return value;
}
main.cpp
int main() {
platformIndependentCode();
return 0;
}
then compiling for linux would be: g++ main.cpp Linux_Platform.h
this clearly wouldn't work and is a loose example, but that's how most do it. They wrap it all up in the same function redefined for each system. You can do the same thing using defines. Something like this:
Platform_Secific.h
#ifdef WINDOWS
int platformIndependentCode() {
do something windows specific;
return value;
}
#else ifdef LINUX
int platformIndependentCode() {
do something linux specific;
return value;
}
#endif
for this method, you can define one or the other. Obviously this needs cleaned up because you could end up defining both and blah blah blah errors errors bugs right? But you get the basic idea I hope. Let me know if you have questions!
@hawks3109 bro your discord? I want to have some discussion over this you
I'm solutions architect, and software engineer in field of networking for around quarter of century and I'm surprised how developers lacks in networking programming knowledge in 21st century, where we live in connected world since decades. I saw such deficiencies even among programmers who were developing 5G. Anyway you're doing excellent job making your videos! Good luck and please keep going. It's a pleasure to watch your videos.
I recently graduated with my bachelors in Computer Science. At my school they did not cover it well. There was very little programming. We mostly learned about the OSI Layers and protocols. Which I think is valuable and it is worth knowing, but we certainly did not learn what we needed to learn to be good engineers. Luckily great resources like Cherno exist- so here I am!
TL;DR: I believe you. I do not think my CS education covered networking very well.
You're right, Marcin. Meanwhile, could you please suggest a learning path (preferably with a few online tutorials) that traverses from fundamentals to expert level knowledge?
Hey Cherno remembered that Linux exists. +1 for more Linux videos please :)
Linux is good but it is hard to develop games on it. And for a Unix/Unix-like system it is better to use BSD anyways.
@@friedrichmyershow is it hard to develop games on linux
@@joshnjoshgaming Ok, here we go. It seems like you're a fanboy. Let me break it down:
1. Fuck Nvidia.
With that out of the way
2. No major engine support. Although, I don't use engine and go low level most of the time, there are times where I use an engine for quick implementations.
3. No debugger. "Oh but that's an IDE thing". No. Linux just particularly sucks at providing an IDE. I use Emacs, even on Windows but I still use Visual Studio for its debugger and LSP. There's nothing like it in the market. No. Jetbrains doesn't come close
4. Collaboration. You know, when you have a job, you don't work on your own. Developers work with you. To make the best of your time, remove the OS barrier.
5. Why would I bother about Windows? Because everyone plays games on Windows so why would I develop on some platform and fix errors on something else?
One tool doesn't fit all. I've been a hardcore linux user for like 5 years. Loved it. But the support isn't there.
@@friedrichmyers i asked a simple question, douche, way to make assumptions and be rude for no reason.
also, its clear you go "low level" (xD) cuz I don't know what engines arent supported, unreal godot and unity all have full linux support.
Godot!
My goal is to become so well - versed with C++ and networking that I can comprehend this video.
I use c++ builder, and they usually bundle a networking library called Indy v10. It really has a lot of client and server networking components with support for SSL. You can do very low level programming for both tcp clients and servers, or add your own web server. I have actually use this to create an email client to aid in automating some email tasks via command line .
awesome video. I'm not sure if you were aware, but Visual Studio has a remote debugging feature. You can edit on Windows, and compile and debug on another machine via ssh. This would save you the trouble of copying the code, compiling the code figuring out how to debug in linux (in case something doesn't work).
Hope this helps in the future.
even better way is to setup a VM in WSL and then you can directly use the VM's terminal (say ubuntu) on the vs code terminal section
About the executable not finding the shared library when you execute it, you could either:
1. set the LD_LIBRARY_PATH to point to where your executable is ( export LD_LIBRARY_PATH=/path/to/shared/lib:$LD_LIBRARY_PATH ). This way the dynamic linker will find the library.
2. ELF files have an entry called rpath. This is used by the dynamic linker to load the shared libraries. When you link the executable with the shared library, you can tell the linker to set rpath to '$ORIGIN' to load libraries in the same directory as the executable.
Tbh I have no idea why 2 is not the default :P
FYI: There is 2 RJ45 termination standard: 568A and 568B. A straight Ethernet cable is a cable that has both ends terminated with 568A or 568B. A crossover cable has one end terminated 568A and the other one is 568B. There is no 568B crossover: it's a 568A.
Hooking 2 PCs back-to-back (i.e. without a switch in between) with an Ethernet cable no longer required a crossover cable IF both interface card are set to 1Gbit or higher. The network cards will do the crossover "internally". It's in the specs of Gigabit network. 10Mbit and 100Mbits connections do require crossover cables even if the card is capable of Gigabit. The same goes when connecting 2 switches (or hubs) using regular network ports.
I think the "TV show" aspect is good, its a lot more fun to watch and it doesn't take any information away from the video. In fact I think its a better learning experience as a whole
I was literally meddling in this subject very recently, I am fortunate that this video would now teach me the more finer points of this very prospect.
@@sirsneakybeaky Honestly it helps to be compelled into using lower level functions to provide a service. You learn a lot more about the system under the hood and are more able to anticipate problems or possible complications later on. I made a webserver in C before and I learned a metric ton about networking that I wouldn't be able to had I not ventured out of my comfort zone. (The entire outside world of which happens to be anything that has to do with networks haha)
Thank you for bringing back the cool colours in the background in your videos.
Seeing you upload a video makes me really excited to watch. Keep it up! I love your content.
I use asio. It is very good and yes, I won't touch anything that requires boost either, but as you note asio has a stand alone project and that's what I use.
why dont you like boost
@@RAHULTMNT100 I don't want a dependency on a rapidly evolving library. Asio library is pretty stable.
Thanks so much for making this video. I am new to C++ and bought some Udemy courses. I was surprised when going through them that I did not see lessons on Networking.
27:31 You have to tell the linker to load the libraries in the local directory.
I remember writing a c# networking system based on tom weiland's original c# networking tutorials and realizing later how much a waste of time it was to write it because the end result ifor all these libraries is the same: send message, send message reliably over udp, receive message. Everything else, you should be doing at the application level anyways so it doesn't make sense to write the actual sockets library unless you're curious to understand it, or if you think you have some ground breaking ideas that will revolutionize how the underlying transport works. So I agree, many times you don't need to understand how something works as long as you can effectively use it, better to concentrate on your own application.
You don't want to just "reliably send mover udp" though.
Sometimes you need reliability and ordering, sometime you just need reliability without necessarily ordering, but most of the time for any real-time application like a game, what you want the most is just the latest one reliably, not caring about lost messages when a newer have been sent.
Then, there are various strategies to archieve that to various trade-off of latency and bandwidth, depending on your bandwidth needs.
(the most efficient trick for low-latency game networking is a lot of redundancy, because you want the lowest latency possible and the bandwidth usage is usually pretty minimal).
@@Kazyek i understand that, i do that at the application level using a tick system, each packet is associated with a tick and I can decide how to handle out of order packets. My point was you can find libraries thay implement the low level transports already and writing them yourself is usually a waste of time unless you have some particular requirements on how the messaging works.
@@phee3D Your point is wrong though. That particular requirement of wanting a mix of reliable communication and minimum-latency communication comes up in any fast action game. I would say though, there could easily be a networking library specific for games that could expose the right interface, I haven't investigated that.
It's also really simple to develop, it's barely an afterthought compared to how you actually architect a game when networked: everything needs to eventually be unified on an event stream regardless if caused by network, user input, game script, response to detected events, "ai" input, etc. then you have to build the game logic underneath that layer. That's without considering the tick rates of concurrent threads, or if you're lock stepped, what your interpolation/extrapolation method is, how the actual architecture works (p2p, single server, or more like an mmo), if the server has complete authority over all actions or if there is some client event triggering with heuristic checks, or so many other strategies. Writing some boiler plate standard code to move bytes is not an issue or difficulty whatsoever.
@@Bozebo you didn't understand what I said. I never said you don't need a mix of reliable communication as well as fastest possible communication. I said these libraries should perform the following functions: send message, send reliable message over udp, receive message. By "send message", the first one in this list, I meant just sending messages as fast as possible, without considering any reliability. I myself am currently making a game where I use unreliable message sending for things such as player position and I also use reliable messages for events such as player death.
Finally! I've been waiting for this exact video for YEARS now
Just wanted to say I've just discovered you're channel, and this is such fantastic content. Really appreciate the hard work you put into these videos, I look forward to following you!
Hey Cherno, can you do a video on "Serialization in C++" for the C++ series....
c++ is powerfull languge when it comes to performonce i remember when i built a webserver using c++ i has so much fun learing how the socket works and serving full static website , great video btw
Yesterday only I learned how to build a simple server using javascript with the help of nodejs. How different will be building a simple server in C++?
@@vivekkoul4428it's very different because javascript is a super high level language, and nodejs abstracts everything away. if you want to learn more about how computers actually work, you should play around with C and C++ for sure
The HTT protocol, the UD protocol, and the TC protocol
Real
27:30 I believe you should use the (already existing) /usr/local/lib directory
then the `export LD_LIBRARY_PATH...` step also wouldn't be necessary
Mannn you brought back so many memories of LAN parties with the crossover cable mention - good times
I remember seeing a fork of the library on cherno's GitHub and kinda guessed a video might come up.. well here it is!
Can't wait to see Cherno do Linux dev, but I have a feeling he's going to avoid it and do some cross compile thing with mingw or something.
I would love to learn more about networking basics so I can understand what the high level process is for making a connection to a server, how to handle basic errors, etc.
I'm happy to have C++ series back
Im using ENet, also an easy to use lightweight UDP based library for typical game networking.
Great Stuff, I love these type of videos where you teach more on things that are not really apart of c++ and where you need outside libraries, and learning those are exetremly confusing e.g learning encryption in c++ took ages and only installing the libraries where a whole process in it of itself
I'm looking forward to that state machine vid
+1
+1
Every CPP dev: "I didn't like all the existing solutions because I didn't want to rely on third party libraries, so I made my own which can can download in the description to rely on in your own code" 😂
(Joking clearly.... glad to see some awesome networking vids on this channel)
I Love C++, it's my favourite programming language. C is also cool. But I love the syntax of C++, I love how it works on basically everything, I love how you can access it from other languages like C#. I also love the performance. Who's with me? :D
The Cherno > Right. So you're sick of being alone. You need to connect with the world.
That hit different.
it's like the cherno wants me to procrastinate work on monday
26:30 you for sure want your executables to be _owned_ by root:root though, so an unprivileged user can't change them.
Generally a "good enough" pattern is to have files chowned to root:root, a nologin user called something like "app-server-headless" that runs your program(s) (usually under systemd nowadays), and then some accounts for your server administrators that have sudo access.
You can restrict the sudo access or start messing with groups or even SELinux if you want to go hard on hardening, but "good enough" works aight.
Bjarne was talking about the C++ standard networking being based on ASIO.
There will be Networking in the C++26 standard most likely. You can search for Networking TS. And the library that is closest to that and will give you the easiest time migrating would be asio. There is a standalone version of asio you can get from ThinkAsync also, no need for the entire boost library.
Honestly I think even for Games asio is a really good fit. But as you said: everyone has their preferences for sure and you are not forced to use that at all also.
Yours seems to be going against the mainstream a little bit. That also shows in your build system choice :p
I searched for Networking TS and it seems that no one is currently working making the changes necessary to get it into C++26. Is It still being worked on?
@@not_everthat happens in C++ committee quite a lot, you can never be fully sure that you'll get that feature in c++26
Honestly I've never had any issue with cpp not having a socket interface. I use cpp all the time at work for windows based applications. When I use it at home, it's always for something OS specific. There aren't many projects where I would choose cpp as the go to language if it needed to be OS agnostic. Obviously it makes sense for a game engine, but I don't build game engines :)
asio has standalone mode that can be used without boost
Neat video. I like how you show how things are setup on Windows. I come from a non-Windows environment, it makes the video easier to follow.
I looked through the comments and could only find like two people addressing this point, so I'll address it myself and add to it, that you should've just used LD_LIBRARY_PATH and set it before calling the program. The path can be relative as well, so subdirectories are fine, but you can even just use '.' in cases where they're in the same directory. Second of all, if the distro you're using is setup properly then you should be using and already have a path for /usr/local/lib or in some cases /usr/local/lib64, though most would only have that if you do any 32-bit cross compiling work. You almost got that one right, but it was backwards because the local comes first. It's where all of the files should be collected that you create on top of the distro files.
The best C++ teacher out there
I can only agree with you
Agreed. I got a job at Tesla because of this man.
1:02 The Standard committee is working on adding a networking library.
12:20 what a time to be alive, where Australian Yugi Moto can teach us about programming.
Seriously how did you do that with your hair?
Networking is so fun, You should also try and make your own integrated networking api. Non-blocking sockets using select or epoll is sooooo fun and gives you so much control. They aren't large APIs honestly.. you can implement a simple non-blocking TCP client/server handler with select or epoll in under 200 lines of code. This would be my honest recommendation for any TCP related networking you need. Though it would work just as well if not better for UDP, and your game engine's overall workflow. I can even see easy integration into your event system.
Yeah, this is more or less what I'd actually like to see 🙌🏽
yeah, i was expecting an epoll() video
thank you for existing
Surely networking TS will be merged with c++26. Surely.
I remember watching your old video on networking on java we are getting older very fast👀
I feel like the next iteration of C++ should have a standard networking implementation.
Even just an open/listen/close/connect. and thats it, would actually be enough.
its actually pretty stupid it doesnt already, should have been in starting at 17 at the latest.
Wow .... in this video a lot of info... super vlogs .... C++ power
Woohoo I made the 2 second cut! :D
Haging? Your server ? Cherno it's just ✨ SURPRISE PENETRATION TEST ✨
Who else watches these videos not understanding a thing cause you are new to programming but still enjoying it so much. Thanks TheCherno!
me
If you're watching for pure enjoyment that is perfectly fine, but just make sure you don't get overwhelmed. There are many years between a new programmer and all of the advanced topics he covers in his videos. Definitely cool to see the "endgame" but make sure you focus on the basics as well! Good luck with the journey :)
@@cyberchef8344 Thanks for the encouraging words! I will indeed take things step by step :)
Really cool video. It's really gonna help me with a project i'm working on
Thanks, that's a great video! I'll definitely follow every single step. :)
Game programmers do it differently - why not the networking TS which is almost part of C++ (and has been for a while) or the full-fledged ASIO?
And it is available for vcpkg - that is all I ask for in a library tbh 😎
nice subtitle at the start. "Hello guys my name is China.."
Sockets are a BSD API. Right down to Winsock actually having BSD copyright notices in it because they copied it. :-)
you mentioned a crossover cable, but you don't actually need one.
the computer can figure it out itself, so a normal cable will work
as you said in start of this vid, the it uses OS libs like winSock, but I believe that is also written in C++.
you make it more interesting than what it is :D, thanks
I've been looking forward to this! 🎉
ASIO is the better part of boost. And it is independent of boost actually and you can have a standalone installation. For a rigorous use of any I/O (not just networking) what I came to understand over 3-4 years is that you absolutely need to have a reactor or proactor design in palce anyway (maybe also with an event loop). That's exactly what ASIO is. Nothing more, nothing less. That's why I even use it on my embedded projects (esp32 with only 512 kb of ram has ported ASIO). It just makes I/O in general more robust and failsafe. The very concept of I/O is very complicated. These designs not only make life easier, they will at the same time help you understand the true nature of the problem and how to solve it.
By the way, about networking peer to peer with Windows for gaming, I was able to do that with a Vista machine back in the day. I was at a friend who didn't have a router (oh, the 2000s), and so I literally just plugged an ethernet cable between our notebooks and used an ad-hoc network option in the Windows network manager. It was surprisingly straightforward, like 1 minute and 10 clicks once I knew where to go. Edit: fairly sure that was also possible over wifi, you could self host a LAN wifi on your notebook, and have other notebooks join, it's been a while since I messed with that though so I don't recall for sure.
even on vacation imma watch your videos!
you have taught me so much I love your videos
Coool, I'm definitely trying this.
I think with modern network adapters you can just use straight cable and it will be fine.
im legit doing this for work right now for the first time lmfao
@15:59 - we can simply use 10ms instead of this long chrono statement since c++14
"Never change C++. Do people say that?" Yes, the "don't break ABI" crowd says it all the time, and they're the reason we can't have nice things.
I’m all for the Linux representation
that one is great, my favourite topic. But how is this one not the part of "c++" playlist? only noticed this video by accident
just what I needed
You should call it the 'HTT Protocol' to confuse everybody 😂
waiting for this video for a while
Protocol is the longest word in the acronym. If you're going to say it anyway, just say hyper text transfer protocol
When I saw on Github "TheCherno has stared GameNetworkingSockets" I knew a new video was cooking. ❤
Great video :D
This came in a timely manner lol
Good work. This is quite useful.
FINALLY!
I cannot agree more with the boost take. Any time you use boost to solve a problem: boost becomes the problem.
I was so happy to see a networking in c++ video, since all the videos I've seen try go into boost::asio just to abstract it away with some custom wrapper class. I never heard of steam's networking library. Please do more Linux videos as well!
I like QT because it is cross-platform. I can compile for Linux, Windows, Android etc
29:07 That server is definitely not headless!
It's just has a command-line UI instead of a GUI...
Sorry but you're wrong here.
"A headless computer is a computer system or device that has been configured to operate without a monitor, keyboard, and mouse. A headless system is typically controlled over a network connection, although some headless system devices require a serial connection to be made over RS-232 for administration of the device." - Wikipedia
The fact that it reads from stdin and writes to stdout makes it possible to redirect it's input/output and disown the process to make it run in the background. One could even run it in `screen` and then detach from it. In all instances, this is a headless application, it does not require a head (monitor) to operate.
@@gnif Yes, exactly, and that was sort of what I was trying to hint at. If you break out of or disconnect from the CUI shown, I suspect the server process also stops along with it... Most traditional Unix commands can also be run in a headless way by means such as you mentioned, or via nohup for instance, so I think it would be a bit of a stretch to call every cmd line tool a "headless configuration" just because of that.
@@benhetland576 Yep, headless means the person operating the computer it's running on doesn't see an interface. So most server programs are, as long as they don't have a TUI or a CUI, and obviously definitely no GUI.
@@anon_y_mousse Isn't TUI just a travel agency? ;-) IIRC we used to call them CLI (command line interface), but nowadays it's too easy to confuse it with the CLR/CLI used with C# (and Active X)... Of course, one might just want to avoid a Terrible User Interface completely 😁
Oh.. and for example Virtual Box can run an entire OS with a GUI in a headless manner too!
@@benhetland576 Back in my Yahoo Chat days we always referred to it as a CUI, but these days I see TUI a lot more because xterm and gnome-terminal are the most common terminal emulators used. I'm good either way, but since people can't seem to agree on terminology I figured I'd cover the bases. As to Virtual Box, yeah, all that's required for it to be headless is no direct user interface.
+1 for more linux walnut content
You should have a look at Holepunching using udp to establish a Peer To Peer connection, basically a connection between two equal machines without a server (Server Less) ...
This isn’t what they call server-less, also you still have to port forward traffic from the peers router to the peers or a 3rd party machine to act as a server for hole punching and it can’t be a chat of more than two attendees
@@CR33D404 it definitely can be a chat for more than two( look at bit torrents) also there is no port forwarding required for hole punching (since that is the entire point of it)
@@CR33D404 Depends on the router configuration. For wireless internet/cell though assume nothing's going to work, you have to use a relay server even for P2P actual hosting (fallback for if can't matchmake a decent host who is not on wireless), as you cannot hole punch!
@@schrottiyhd6776 but it still need a 3rd party machine to bypass the need of port forwarding or the limitation of CGNAT and to distribute packets to other machines, I’m i missing smth?
@@Bozebo that’s why a server-client is best suited for this purpose
You shouldn't need the `protobuf-compiler` package for running a binary. The compiler is the part that takes in a `.proto` file and generates code in C++ or another language for serialising/deserialising the protocol. For running your binary you should only need one of the `libprotobuf` packages (in this case it looks like `libprotobuf23` was installed as a dependency of `protobuf-compiler`, and that would give you the `libprotobuf.so.23` shared library that you needed).
good video this is something i like to see from u!
There's no networking in C++ because protocols like TCP and UDP, etc. are only about 40 years old which means they're not considered mature enough for the C++ standard.
There was a strong push on the committee to add networking to the standard. In the end it's quite some effort to get it to the level of maturity C++ guarantees, and members choose features that are better suited for their skillset. ^^ but if you want to do it nobody is holding you back.
In the HTT protocol.
I love Cherno's videos for many reasons, his preference for GUI and Windows is absolutely 2 of them. I have lost count of how many times I edited a file in Windows and uploaded it to the server just to avoid having to edit it on the server CL. lol
Could it be that Valve made GNS to support their games? Or, is there no connection?
THis is what ive been waiting for
We need vulkan series like openGL
YES! That would be awesome. That would be awesome!