i created my own protocol for my games...
HTML-код
- Опубликовано: 10 окт 2024
- / theprimeagen
Best Way To Support Me
Become a backend engineer. Its my favorite site
boot.dev/?prom...
This is also the best way to support me is to support yourself becoming a better backend engineer.
MY MAIN YT CHANNEL: Has well edited engineering videos
/ theprimeagen
Discord
/ discord
Have something for me to read or react to?: / theprimeagen
Kinesis Advantage 360: bit.ly/Prime-K...
Get production ready SQLite with Turso: turso.tech/dee...
Watching people who are great at using vim is like watching people training at the gym: you find them sexy, you want to be like them, but you don't want to go through the effort
i like the way you worded that
This is perfeft
not even worth the effort for me. I spend maybe 5% of the time actually coding, the rest is switching between files, peeking at classes, debugging. All the shortcuts don't mean diddly squat for me. But visual studio's tab layout and ability to peek at stuff really quickly helps.
Vim speeds up switching files, peeking at classes, and debugging, and much more. Vim isnt just about the improved speed writing code. Vim speeds up window management, navigating files, moving window panes, etc..
@@moonasha hm really? I am working in a medium sized go project in lazyvim currently and few months ago used vs code. To me, all of the things you said feel much more comfortable in it. Debugging is basically on par (weird default shortcuts), but for me project navigation, or switching between files is much easier in vim.
These video formats are my favorite. Love the content
Man, really wanna see more of these kinds of videos - your deep dive into this, showcasing also your knowledge of things like TCP protocol and websockets, is super interesting :)
"[...]I think that's probably more than enough, than I need" You're just asking for trouble now.
That's what the version tag is for
"kinda FUN"
(laughs in 9999 possible vulnerabilities)
Kinda the only way to make profitable realtime* multiplayer games unfortunately though
Let's have Thor ethically hack his servers 😂😂😂
first make shit work, then make it safe. Securing a protocol/channel is not an easy task, and you probably need the support of your Russian/Asian hacker friend to do it.
@@rusting_in_peace Not quite the case with multiplayer games too, if you don't plan the architecture ahead, and consider the gameplay implications of each architecture, you can end up with a networking model that will never be cheat proof, like making a peer to peer competitive shooter
@@AstuteJoe you have a point. And I think even now, hundreds of AAA game's middleware engineers must be working on it constantly to find an effective way...but the nature of the domain is what should be addressed on a case-by-case basis.
Yes, I did. Unfortunately it was written in lua, so as you can imagine, the moment I stopped sending string identifiers was the moment it kind of lost its ground.
I've built my own network format, it was horrible to debug because it was specifically designed to resist casual inspection -- using a hash-based addressing scheme where each station needed to use its cryptographic key to decide whether or not any given packet was addressed to and/or meant to be relayed by them.
0:29 I've made so many protocols at this point, from binary to text protocols, that this is child's play for me. My recommendation for anyone's first network protocol: Two-way JSON separated by newlines. Is it efficient? Nope. JSON encoding/decoding performance is always terrible. Will it work surprisingly well? Yup! Can you easily interop fairly complex data across multiple languages and avoid a ton of bugs and security pitfalls? Sure. Can you alter it without worrying about its structure? Absolutely.
I created my protocol 10 years ago, consider a short in the packet for routing, do not use a int for len unless you want recieve 2 gb packets, handle all connections and packets in a own async thread pool. the CPU has a fast array copy instruction, keep that in mind.
I've been using little-endian in my protocols for years, just because all the major architectures use it. It simplifies a lot of code and saves the small perf hit of having to convert back and forth constantly.
"if count == 5" should be "if count == BUF_COUNT", just sayin
I played with that stuff 2 years ago. I did almost the same except I didn't have an encoding flag but instead I had a packageId flag. You may have a situation when your client sends multiple packages and the server can spend a different amount of time handling them. Client sample sequence of events:
Send1, send2, send3, receive response1, receive3, send4, receive2, receive4
You may have 2 types of packages: notifications (fire and forget), request, and response.
I love these videos, they're so inspiring. I started building a text based adventure game to learn about OOP and some design patterns, but now I'm thinking about how I could make it multiplayer.
Remember the Amiga IFF ("Interchange File Format")? This brings back lots of fond memories. 🙂 Thanks for sharing!
sometimes in my nightmares after i wake up screaming
I've created my own protocol but with variable length integers in header, because it is more _fun._
This is my cup of tea. I'm not a developer by trade but I've been working on a Pico powered hobby project, in rust because of course. I've written an extensive low level TCP protocol for data transfer, super lightweight, extensible, variable packet sizes and data types etc and with a nice shared library so that I can use the same core code for both the server (again, in rust) and the pico client. You learn a LOT when implementing things at this level and its so satisfying when you get it working end to end. Got a simple UDP discovery protocol too, which was fun to do
More of these videos please! love these insights and learn heaps more then the react vidoes
Love these videos, you’re very good at describing and teaching, excellent ❤
Fixed-length encoding for the length header. Gigachad.
I don't know if it was a conscious choice, but using variable-length integers for the length header drastically increases the complexity of parsing the header in a safe/secure way that doesn't open you up to DoS attacks that come from carefully engineered messages.
The assert around 7:14 checking that the packet length is greater than 0 is a DoS waiting to happen (a message with no body will crash the server).
As for using variable length integers in headers, beside overflows in naive parsing, I fail to see the issue with them. I agree more considerations and processing are required to handle variable length fields and their flexibility is really too useful but IMHO the difference between fixed size and variable size isn't that large and you can reuse the code elsewhere.
Unless you plan to decode raw messages by hand (in this case, a decoding util is pretty good), I fail to see the difference.
11:32 wait prime is not raw dogging git cli?
That's very similar to the Napster protocol. I made a similar one to communicate with a Windows 3.11 chat app I'm building.
The difference is that the actual values are sent in a specific order separated by spaces after the length.
What? You've got a nice encoding-decoding setup going and you're NOT PBTing that shit? HAWK TUA ON THAT CODE!
Slapping some Property-Based Testing on code that bijective code is the best you can do here!
Dude, you are inspiring!
Microsoft recall is enabled by default in the latest Windows update!!!!!!!!! update 24H2
If the packet is being sent via UDP you don't have to send the length because the UDP packet has a length associated with it and it will be received as a discrete message. If you send the packet via TCP (unlikely to be a good idea for real time game data,) you absolutely need a length to know where in the stream a particular message ends, or you have to do something ugly like a delimiter or fixed size messages or something.
There isn't really any reason to use bigendian. Virtually all modern CPUs use little endian though it is pretty trivial to byteswap from big endian. The only potential advantage is that reading the data in hex format will be easier with bigendian but there isn't any reason to do that when you developed the protocol and clearly have code to parse it and present it to you in a readable fashion. It isn't very wasteful but unless you're doing raw sockets or something there is no reason to do big endian.
Personally I really wish go had a c struct compatibility library similar to the python struct library. That would take care of all the padding and you could just use structures fill them with data and send them through sockets without serialising anything (as long as all the struct members are simple data types or structs composed of them with no pointers.) I think you can do this with unsafe go but then you lose a bunch of the benefits of using go. I settled on just using protobufs for my protocols in go. They aren't for a game but likely would be just fine for basically any game someone might write and I can generate code for all the other languages I use without doing anything. I almost went with CapNProto but it didn't support all the languages I jump between for my side projects.
Was this supposed to be on the Vimagen?
Ya i guess he uploaded in the wrong channel probably :)
May i know how you type those sequence diagrams easily? I assume it's some Vim macro but i don't use Vim so i don't know but i'd like to learn. Seems pretty useful.
Wait untill he finds out about event driven architectures, he will have no hair left.
I need the matrix so I can download programming knowledge like this guy. He's so fast
ligmuh (I am scared let's watch this 😂)
Such a great experience in having a horrible time... my whole existence
Kinda wondering if just having packet[2]+packet[3]*256 (or packet[3]+packet[2]*256 depending on how you wrote it) would have any significant speed difference over a function call that basically does... just that. An optimizing compiler should inline it, but...
This was really good.
Lol with those asserts and break the world all it takes is non ECC memory to fail in the right place and it all falls apart.
4:05, if PACKET_ ... _SIZE is a constant, shouldn't this assert be 'n < PACKET...'?
4:08, literal numbers... the most underestimated issue of all time! They should be MAX_TYPE_SIZE and ENCOD_SHIFT.
6:36, couldn't it be bigger? In this case, your if would fail.
I worked on a game that had this type of special protocol
As to creating your own packet structure.... Do you have to have succeeded for it to count?
Nice protocol
I think little-endian makes more sense (even though it's not the network byte order), just because most of the architectures are little-endian now anyway. Better pay a penalty for conversion only on the outlier architectures (big-endian, if they even exist as your clients), than pay for it everywhere in a wasteful manner.
Just where do you find time after work??
He no longer works at Netflix, he is full time e celeb.
Anyone knows how he did the markdown graphics?
Probably some vim macro
What's the fonts/plugin name which Prime is using here? The != and
they are ligatures
The font is JetBrainsMono and those are ligatures as another commenter already mentioned. I'm not sure but I think this is the default font for Ghostty. It doesn't look like Prime has done much if any customization.
@@benbrook469 I learned somethong new today, thanks man!
@@arashiryuu1624 Thanks!
You didn't use Mermaid in your Markdown? Shame! :)
Is that csharp ?
6c is lowercase, the thumbnail has uppercase L
such facts, well observed
Welcome💙 🔥🔥🔥
All the time.
I didn't understand anything, but it was fun watching 😅
okay but what is a framer
I already knew how to do this, just wasn’t gonna tell u 😏
Now do it with UDP, please!
Basically the same thing. He can either fill a buffer with multiple packets and send that as a datagram (looping on read), or simply send/recv on packet per datagram. TCP is usually slightly more involved because you need to know how to parse the stream and to account for short reads and so on. Which requires lengths so as to know when the full packet (or plural) has arrived. He has lengths embedded in his packets so it's good.
@@justanothercomment416 udp gets fun when you need: Reliability Types, ACKs, NAKs, Ordering Channels, Split Packets, Priorities
you can send empty packets for keep alive :)
The kernel should automatically send keep alive packets (assuming the socket type is tcp)
Realtime communication protocols aren't tcp. I also believe you can restrict usage of tcp keep alive for apps on some operating systems.
it this go?
Naive in so many ways from the start. Does it get better? Where is the error correction? Where is the message resync?
how did u made the ascii tables
Plenty of online generators for it
Go is so damn beautiful I really need to learn it and find a project to use it on
why did you choose 8 bits for the version? Wouldn't like maybe even 4 be sufficient?
If you're careful, but if you run fast and break things constantly... Maybe he should have gone bigger 🤣
@@chinoto1 haha 🤣
Ligma
Kinda fun, is just coping because I don't have a job.. 🤣 commit to open source create a game create protocol bla bla.. still no job fuck this market
First
tldr: always add version byte... (tes rest can be ignored 😌)
this is not funny, I almost died of ligma a couple years ago
There's no money in creating a protocol for funsies therefore none of the new devs are going to do it.
What’s Ligma
ligma balls
no ty
binary.BigEndian FTW!
msgpack-rpc and yolo
first