Avey delivers a crisp, pragmatic demonstration of systems-level networking that highlights C3’s potential to modernize legacy C workflows. It is a sophisticated yet accessible deep dive into the mechanics of socket primitives.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
C3 Networking | TCP ServerAdded:
I like C3, but I find the documentation lacking just a little bit. Maybe one day I'll contribute. And I always think the best way to learn a language is just build something with it. So, in this video, we're going to create a TCP server with C3 without great documentation or a network guide to programming like Beej's Guide. Okay, let's create our project. I almost typed out let's create a project. Uh C3 a knit. I'm going to call this C3 chat or C3 hat, I guess. Oh, well, we need C3 C, sorry. Oh, I didn't mention this, but I am going to create a simple chat application with C3. It's going to span multiple videos. So, things will be broken up in bite-size chunks. Okay, so how would we set this up? In C, we would probably get our sock outer info um and then get set up our socket.
So, with C3, we got to go to the documentation, go to docs, and control K, and I'm going to search for socket.
So, there's a TCP server socket. That sounds interesting. And let's see, there's a function to listen. We got to pass a host, a uint port, a backlog, that's how many connections at once.
We have options and IP protocol. So, that was TCP server socket questionable called server equals I think TCP listen uh string host. We're going to set that to localhost and uint port, we'll set that to I don't know, 9500, that's always good. And uint backlog, uh we'll have 100 connections at once for now. And finally, we had sock options and IP protocol. To figure something out, I think we have to actually go to the source in GitHub. So, I'm lib STD and we're going to go Where we going to go again? Oh, here's a socket. So, we can see our socket is native sock, which is OS socket. Okay, well, yeah, it's going to do all this for us. All right, don't have to set that up. So, I think I can just call listen and be able to get everything. But we were looking for What were we looking for again? The options.
Might be in TCP, let's see. Oh, here's all the functions. Anyway, let's put our start by putting our Put our host, our port, backlog, and why my options to be something. All right, there is examples.
So, the C3 showcase, all these links will be in the description. We have Let's see, there's got to be something in here.
HTTP server. Okay, here we go. TCP listen. They have a config, a port, backlog, net. Socket option reuse addr.
Okay, I haven't imported net. Do I need to I just probably do sock socket options. What What was it? Reuse addr.
And then we want IP protocol 4. I mean, I want IP protocol V4. I don't want 6. Since this is so big, I'm going to go ahead and put this on multiple lines, I guess. And since we have a questionable TCP server socket, we probably need to catch this. If catch error equals server, we need to Let's just print out unable to create server socket and return -1. All right, let's go ahead and compile, see what happens here. C3 C build. Okay, socket options cannot be found. Did I spell it right?
Maybe I didn't. Socket option, I put options. Okay, that makes a difference.
Now, we're going to build again. Error enum IP protocol can only be cast to an int type. Passing directly sock option is not valid. So, IP protocol. Saying this IP protocol can't be cast.
You know what? Sock option is three dots. V args. Yep, so usually parameter after [clears throat] V args would never be assigned. So, it's got a default. But if we want to set it, uh-huh, IP_protocol is that. Now, if we build again, I think we'll be good. There we go. Now, let's just run it just to see what happens. If errors Okay, we're good. We get the socket. Let's go look at the example.
All right, so we need to probably close the server. They're throwing the error or they're going to crash if the server is not going to close. We can probably do that with our um our server uh we set up the socket here. Instead of catching the error, we could probably just go ahead and put um two there and it probably will print out the error. I don't know how to fool it into saying our server is not going to set up. So, instead, we need to defer our close. I think I'm going to catch it and just print out like I've been doing.
I don't know if I need to return because this is deferring, so at the very end, once it gets right before return zero, it's actually going to call this and then do this. If it can't close, it's going to error, but we're going to close the application anyways. Now, at this point, I think we're ready to I believe let's check the example again because they have this set up and working.
Yep. So, we have a accept on our server get server. Our server and get a basically a client socket and do something with it. So, I'm going to go while true. Let me go back to the documentation and look up TCP socket connect or accept. I'm sorry, yes. So, we need the server socket. Call this client equals accept and that was a pointer to a TCP server socket. So, I'll just if catch error equals client, we got an error and we want to continue and wait for another client to connect.
And we need to do our defer block again.
If catch error equals client.close and we should probably just go ahead and continue. I don't know if I need it cuz once again, defer waits to the end of this Once it goes out of scope, it's going to call this. So, once we get to the end of this while loop, this client will no longer be in scope, so it will try to close this. So, I have socket close. There's probably socket read.
Let's go to Let's go back to C3's GitHub. So, this is This is a struct and you can put functions on structs, so we don't have to pass everything in. So, it's going to have the self.sock, as you can see here.
So, this is accepting a char array or slice of bytes. So, let's set up a char buffer. Um I think the normal size is 4096.
So, I think I've done this before. While try use size red equals client.
read and we need to buffer in there. So, let me just see if I can print that out.
I have no idea. So, whatever we're going to send, I'm just going to use curl for example, it's probably not going to be greater than 4096, so that'll all be in one thing. No, yeah. Whoops, we need We need the library. We need TCP accept.
Build again. Uh [clears throat] continue is not allowed. Must not be allowed in a defer. You can't continue or defer from a continue or return from a defer. So, let me go ahead and do that. This is going to go to end of scope anyway, so I don't think it matters. What other errors do we have here?
Just warning, this code will never execute return zero after the while cuz we're never going to exit. Um localhost 9500, I believe. Okay, so let's go over here. 9500, see what happens. I get nothing. Ah, yeah, so there's got to be a way to convert that. Create a string from char pointer and use size, which is what we have. So, cast it to a string and our buffer and how much we read.
That makes sense to me, I guess. We cast it to a string and then we treat it as a slice, I believe, from the beginning all the way till what's read.
Okay, same warning we had before. Build.
Go back over here.
Same thing. Okay, awesome. But at some point, this is going to be a chat server. So, I think I don't want to put this leave this in this buffer here. I probably want to put it in some kind of list or vector or something. All right, so here we go. Dynamic arrays and lists, that's what we want. So, it's just a list string in the STD collections. Down here, I'll make a list string. [snorts] Let's call it data for now. And then we initialize with mem. That's not even declared. I guess it's a keyword. In it mem. See what happens there. And what can we do with that? We can push.
So, we can just push what we got here.
So, data.push, we're going to do string buffer, how much is red. There's going to be parsing required later cuz I think it's going to put whole thing in that first list item. So, for each piece of data item in the data, we're just going to print out that real quick. It's probably going to be the same thing, but let's build, run that, and do a curl request.
Got nothing. What happened? Well, we should check if red is less than I probably should create a variable for that. Magic numbers.
If it's less than the buffer size for each loop, we need to break, I believe.
Okay, there we go. Perfect. With that, there's a couple more things I want to fix. That is a bool should quit equals false, and then a const int buff size, I guess, 4096.
While we should not quit, and then we got to fix the buffer sizes, and then we can see about quitting. So, if there is a specific word passed to the server, maybe we quit. Cool.
String.contains item.contains, let's just say quit, then should quit equals true. Ah, no warnings this time.
I like that. Let's send hello.
Doesn't close. Let's try sending What did I say? Quit. And the application closed. In future videos, we're going to clean up this code and probably put all that in functions, so it's not in main.
We're going to create a client, so it can send messages, and we're probably going to set up some kind of threading on the server, and maybe put it in some kind of GUI with Raylib and Raygui.
It's all that is, easier said than done, but I'm going to try to keep it simple because this is just for learning and better understanding the language C3.
Awesome. Way to level up by doing. The code will be hosted on GitLab. Link will be in the description. And thanks for watching. Be sure to subscribe, like, share, and comment to defeat that algo monster.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











