Making Minimalist Chat Server in C on Linux

  Рет қаралды 38,477

Nir Lichtman

Nir Lichtman

4 ай бұрын

Making a simple chat server and client using the C Programming Language and Linux Socket API.
Code:
gist.github.com/nir9/f5a7307a...

Пікірлер: 112
@Kirmo13
@Kirmo13 4 ай бұрын
Windows as os with a custom tiling window manager, running Linux command shell using WSL and vim as your editor. A combination I've never seen 👏
@JayHey111
@JayHey111 3 ай бұрын
what the actual fuck? how do you do that?
@JayHey111
@JayHey111 3 ай бұрын
i thought it was just a themed terminal application to look like the terminal from win 11
@guigs4467
@guigs4467 3 ай бұрын
actual psychopath
@JayHey111
@JayHey111 3 ай бұрын
@@guigs4467 yes a bit
@A9wpd
@A9wpd 3 ай бұрын
talk to those who uses a old pc where he do tasks like linux on windows 10.
@space9824
@space9824 4 ай бұрын
I love the way you just get right down to the business of writing code, it's so refreshing.
@Crux161
@Crux161 4 ай бұрын
The C classes I _should have taken_ 😅 better late than never
@anggaradotnet
@anggaradotnet 3 ай бұрын
the way you find the solution by opening the manual on the terminal really inspired me.. darn this is the real programming activity... gonna learn more about C
@pinuxman802
@pinuxman802 4 ай бұрын
You have a great skill in using man pages btw
@KaiusKC
@KaiusKC 4 ай бұрын
Literally RTFM
@MadMathMike
@MadMathMike 4 ай бұрын
Man I love this stuff. It really makes C feel much more accessible. Forgive me if you've talked about this before, but how do you feel about some of the relatively newer languages like Rust and Zig? (Especially Zig).
@nirlichtman
@nirlichtman 4 ай бұрын
They look very cool, I haven't learned them yet, but I do definitely plan to do that - especially Rust since there is an interesting open source project called Ruffle which is written in that language and it would be nice to be able to contribute.
@MadMathMike
@MadMathMike 4 ай бұрын
@@nirlichtman Right on. 🙂 I've been learning a little Rust (emphasis on "little"), but I've really liked it. I'll have to check out Ruffle to see what that is about. Zig has been catching my eye lately, so I'd be interested in your thoughts on it if/when you get around to it. I'd definitely watch any videos you share on it!
@BrunoBernard-kn6vt
@BrunoBernard-kn6vt 4 ай бұрын
Rust is focused on memory safety. Example if you never called free() or deallocate memory before, it means your C code has some memory leak. Example you create a variable A this is saved into memory, you need to deallocate it from memory manually. With Rust you are basically writing C but reducing your memory leak (near to zero). On another hand Zig has a different approach, it is not like C at all. It is mostly like Javascript but much better with the speed of C. Easy to pick up. Zig primary goals are easy maintenance and ease of use. Rust is a great alternative to C or C++, Zig is a great alternative to Rust because of it's easy of use (Rust has a steep learning curve btw). People who uses Zig writes low level code, because it is quite complex and Zig leverage that part. Rust will cover 99% of what you need. Go with Zig is you are doing low level programming like writing your own linux kernel for example. Rust is too strict sometimes. Zig let you do whatever you want. Writing safe code in Rust and Zig is simple. Writing unsafe code (mostly low level stuff) in Rust is difficult. Writing unsafe code in Zig is easy. Got it ?
@tweetyguy7347
@tweetyguy7347 26 күн бұрын
@@BrunoBernard-kn6vtI feel that rusts syntax is just weird. As a c++ coder looking at rust code makes me want to gouge my eyes out. Like what’s the design choice of :’s?? I’d much prefer if I could get that rust safety without ugly syntax
@BrunoBernard-kn6vt
@BrunoBernard-kn6vt 26 күн бұрын
@@tweetyguy7347 well if you want to move to a better syntax consider zig
@baptistepasquier4174
@baptistepasquier4174 4 ай бұрын
Very good video !! Loving those short tutorials. I've done quite a similar project but not by using socket but UNIX signals.
@TheBrunoRM
@TheBrunoRM 3 ай бұрын
one of the best programming videos I've ever seen on youtube. great job!!
@abrahampo1801
@abrahampo1801 3 ай бұрын
Men i cant get rid of using copilot and this guy doesnt need internet at all, epic dude
@alangraton2000
@alangraton2000 3 ай бұрын
Pretty neat man. I loved (still loving) C during college
@pavfrang
@pavfrang 4 ай бұрын
Another exceptional video, thank you!
@TheMasterAbdul
@TheMasterAbdul 4 ай бұрын
Keep up the amazing work, it is fun to see :)
@saturdaysequalsyouth
@saturdaysequalsyouth 4 ай бұрын
Good video. Have you thought about giving like a 1-2 minute high level overview of what the application is supposed to do and how it works before diving into code and man pages?
@nirlichtman
@nirlichtman 4 ай бұрын
Thanks! That is a good idea, it can help give more context.
@th3j0t46
@th3j0t46 3 ай бұрын
Did something like this on my 2nd year at college :)) Good stuff!
@sweetbabyalaska
@sweetbabyalaska 4 ай бұрын
I love how you can just use man for pretty much everything in C. I wish more languages and tools adopted this (but its a lot of work)
@CYBERNETIC-ANGEL
@CYBERNETIC-ANGEL 2 ай бұрын
learned a lot from this video. thanks
@guillermoezequielperna9674
@guillermoezequielperna9674 4 ай бұрын
Thank you very much for this content.
@MeineRespectirung
@MeineRespectirung 4 ай бұрын
Great video! By the way, since we're talking about Rust and memory safety - maybe you can do video about malloc() and free()? Also you may combine it with the topic of strings. I know this is a cliché, but it will be fun to see how you're talking about it in your unique 10-minute style video.
@nirlichtman
@nirlichtman 4 ай бұрын
Thanks, yes :)
@mh7200
@mh7200 3 ай бұрын
I use the Same setup! Nice 👍🏻
@chroanamandros6820
@chroanamandros6820 4 ай бұрын
I dont write C but man you make it look easyyy Great vidddd❤❤
@onurguzel16
@onurguzel16 4 ай бұрын
Nice tutorial Nir, however would you please let me know why you used MAKE instead of CL while compiling this time, unlike previous videos? Is it because you never used Microsoft headers (no MSVC) and it was pure C? Keep up good work, regards!
@nirlichtman
@nirlichtman 4 ай бұрын
Thanks! In this video I programmed on Linux so I used WSL with Debian, and I used a trick in which you can run make command without a Makefile and it will use the default compiler, on my Linux setup - the default compiler is gcc.
@thatonemailbox
@thatonemailbox 4 ай бұрын
I love your content! Could you write a minimalist regular expression engine at some point?
@nirlichtman
@nirlichtman 4 ай бұрын
Thanks :) Yes, that is a good idea!
@urs4n313
@urs4n313 4 ай бұрын
Depending on which version of vim/neovim you're using, you might be able to use the `:Man` command to open the man page in vim/neovim. I use neovim and I mapped that to `k` and that would save all the back and forth between the two tmux panes. Otherwise, you should lookup `:h K` because you can set it to do something similar. Might make the video less clear though.
@nirlichtman
@nirlichtman 4 ай бұрын
Yah the :Man command is great but I prefer using man in the terminal on my videos so it will be more universally clear (and not too specific to Vim). Actually, for the windowing in this case I use the built in Vim windows and not tmux.
@leonvolq6179
@leonvolq6179 4 ай бұрын
The peace is perfect, not to slow not too fast 🎉
@quicksolution5881
@quicksolution5881 3 ай бұрын
Umm.. 23.6K subscribers??? Only??? The fact alone you started writing on 0th second the video began is enough for me to sub tbh
@nirlichtman
@nirlichtman 3 ай бұрын
Thanks :)
@mumk
@mumk 4 ай бұрын
interesting, thanks
@shahidkhan69
@shahidkhan69 4 ай бұрын
I’ve always wondered how async code waits for IO. Bow I know, the poll function. Thanks
@nirlichtman
@nirlichtman 4 ай бұрын
Poll is very useful in case you don't want to fork another process and still need to wait for more than one file descriptor
@angelffg
@angelffg 4 ай бұрын
Excellent video! Good content! Nir, please explain to us how we can prepare a Windows machine to compile in C just like you do. The make file is not in git. Make is an instruction that gcc implicitly does? In the past, I used Clipper5 and Make and CL were batch files that created an EXE from a source program. We also want to know, how did you install the Tile Windows Manager? What her name? How can we install it? Thank you! Congratulations, you are the best!
@nirlichtman
@nirlichtman 4 ай бұрын
Thanks! :) In this video I am using WSL with Debian. About the make command, it is possible to run make without a Makefile, in which case it will just use default rules and all I need to do is pass the name of the C file - in my setup it will use by default gcc to compile. The tiling window manager I use is called dwm-win32, more info about the setup in the welcome link on my channel.
@angelffg
@angelffg 4 ай бұрын
@@nirlichtman Thanks Nir, Your videos are very good. It is a good gift for learning. Thank you for supporting us in learning more about C Language and other computer science things.
@ultratoz
@ultratoz 4 ай бұрын
Your videos are very refreshing. A question. When I run on linux "man sockaddr" - "No manual entry for sockaddr". I run (WSL/Ubuntu) - what more do I need to install? Keep em coming
@nirlichtman
@nirlichtman 3 ай бұрын
Do you have manpages-dev package installed?
@nickbelanger5225
@nickbelanger5225 4 ай бұрын
Do you write these programs for reference before doing these videos? Or do you just know the std lib that well? Man pages are great; it's why I love unix-type OS's and C but I run into the "don't know what I don't know", problem where I'm happy to RTFM if only I knew which utilities to check given the functionality I need.
@nirlichtman
@nirlichtman 4 ай бұрын
Before making these videos, I write a POC to practice and make sure I know all the functions needed. During when I write the POC, I mostly like working with the man pages whenever I can and also exploring additional functions by starting with functions I know and then at the bottom of the man page there is "see also" which helps discover more stuff. If you want some tips to navigate man pages, I have a video on that :)
@shahidkhan69
@shahidkhan69 4 ай бұрын
I built a UDP server with audio. Used a relay to get around NAT but sound is cutting. I think I need to implement RTP
@KaranChecker
@KaranChecker 4 ай бұрын
Amazing code. Maybe use a softer keyboard while recording.
@justinnamilee
@justinnamilee 4 ай бұрын
Neato.
@novus7456
@novus7456 4 ай бұрын
Great video as always. I do have a small suggestion to improve your videos. The sound of your keyboard is quite a bit too loud compared to your voice.
@nirlichtman
@nirlichtman 4 ай бұрын
Thanks for the feedback 👍
@bhavyakukkar
@bhavyakukkar 4 ай бұрын
did you know that hitting Shift-K at the start of a word in vim searches for its manpage in a new window? cool trick that seems like it would have applied a lot in this video
@nirlichtman
@nirlichtman 4 ай бұрын
Yah Shift+K is cool, but the problem is that the window that is opened fills the whole screen and I like working with the man pages in a split view with the code. There is also the :Man command which does open the man page in a new split Vim buffer, but I still prefer working with the "man" command in the terminal (on my videos) so it won't confuse people that are using editors other than Vim.
@buraksoykan2985
@buraksoykan2985 3 ай бұрын
Ecole 42, Minitalk project same like that
@Benjaneb
@Benjaneb 4 ай бұрын
How do you open a terminal split on top inside vim? I don't see you first splitting and then running :terminal. Or have you just set a keymap for that?
@pajeetsingh
@pajeetsingh 4 ай бұрын
:sp
@Benjaneb
@Benjaneb 4 ай бұрын
@@pajeetsingh This only splits the editor, not open a terminal
@pajeetsingh
@pajeetsingh 4 ай бұрын
He is using dwm I guess so it has bindings to do so.@@Benjaneb
@Benjaneb
@Benjaneb 4 ай бұрын
​@@pajeetsingh I see now that the first time he opens the terminal he does just run :term but usually that just opens a terminal instead of the editor, not split.
@Benjaneb
@Benjaneb 4 ай бұрын
Ok nvm apparently it's just because I use neovim, works like in the video with regular vim
@ItsCOMMANDer_
@ItsCOMMANDer_ 4 ай бұрын
How did you split your terminal lile that? It looks nice
@nirlichtman
@nirlichtman 4 ай бұрын
Thanks! I use the window splitting feature built-in Vim, I have a video about that on my "Vim Tips" playlist
@NostraDavid2
@NostraDavid2 4 ай бұрын
If you want to do the same in bash, then tmux or screen (great name, I know...) are your friends. They'll be a pain to get used to, but once you are, you'll be happy you spent the time. Being able to split bash into separate panes and/or pages is invaluable.
@guilherme5094
@guilherme5094 4 ай бұрын
👍👍!
@asifzamanpls
@asifzamanpls 4 ай бұрын
great video but i must ask, howd you get dwm working on windows?
@nirlichtman
@nirlichtman 4 ай бұрын
In this video I used dwm-win32 but I recently decided to stop using it due to bugs and overcomplication of the code, I am now working on making a new minimalist tiling window manager for Windows which I also started using myself (my most recent video is about this project)
@asifzamanpls
@asifzamanpls 4 ай бұрын
@@nirlichtman Interesting, I've started playing around with dwm-win32 and I do notice some bugs. Will follow the development of your window manager. Great stuff!
@matweyrybakovskiy2952
@matweyrybakovskiy2952 4 ай бұрын
Hey! Can you please show how to use unicode strings in C? For example, how to make this chat send not only english messages? Thank a lot for your videos!
@nirlichtman
@nirlichtman 4 ай бұрын
Actually, this chat program also supports international UTF-8 languages, since it just sends the bytes of the messages and doesn't do anything specific that assumes the characters are ASCII only, but I do plan a video about UTF-8 and UTF-16, interesting topics :)
@matweyrybakovskiy2952
@matweyrybakovskiy2952 4 ай бұрын
@@nirlichtman Thank you)
@tomershechner7449
@tomershechner7449 3 ай бұрын
רמה גבוהה ביותר. יש לך סגנון ייחודי, מסביר מה אתה עושה בלי הקדמות מיותרות. אהבתי במיוחד את השימוש הנרחב שלך בדפי מן, מראה איך להגיע לפתרון מהר בלי לרוץ כל שנייה לדפדפן.
@nirlichtman
@nirlichtman 3 ай бұрын
תודה רבה! :)
@TunifyBasic
@TunifyBasic 4 ай бұрын
you need to do a setsockopt SOCK_REUSE or something like that
@robbirobson7330
@robbirobson7330 4 ай бұрын
its basically like python
@Kyoz
@Kyoz 4 ай бұрын
🤍 Love every video that has C or minimalist in the title.
@justinalejo4187
@justinalejo4187 3 ай бұрын
how do you get your terminal and file to do that on the same tab?
@nirlichtman
@nirlichtman 3 ай бұрын
You mean how I split the source code and the terminal? I use Vim window splitting, I have a video about that on the channel on my playlist "Vim Tips"
@rian0xFFF
@rian0xFFF 4 ай бұрын
help: better way to add data into a linked list without loops or inserting it directly? I need to read a file
@NostraDavid2
@NostraDavid2 4 ай бұрын
What do you intend to do? Create an empty linked list, then expand its size and then add items? I'm unsure what you want to do.
@rian0xFFF
@rian0xFFF 4 ай бұрын
​@@NostraDavid2 I have a struct struct node { char something[10]; struct node *next; } I have different values to add into node.something through a function function add(struct node **n, value) i'm tottaly blind on how i'm gonna add values to this node and continue to next, because the function is being called inside a loop
@braz1080
@braz1080 4 ай бұрын
I followed this code line by line and compiled it with gcc on mac, but messages are not displayed on the server/client.
@antoniomontana351
@antoniomontana351 4 ай бұрын
check your code thoroughly, cc version and libraries. Try to compile the code you have written in somewhere else.
@nirlichtman
@nirlichtman 4 ай бұрын
Interesting try running it with ltrace/strace to see if there is any problem, also you can check the link in the description to view the code I wrote in the video
@braz1080
@braz1080 4 ай бұрын
@@nirlichtman Retried it on ubuntu and it works as expected. I guess it was an issue of incompatibiity with Mac headers. I thought since Mac is unix it should work.
@spyrosdev2533
@spyrosdev2533 3 ай бұрын
please tell me what font you use!
@nirlichtman
@nirlichtman 3 ай бұрын
On this vid I use my WSL setup on Windows Terminal and the terminal is configured with the Cascadia Mono font.
@sournois90
@sournois90 4 ай бұрын
what's the name of the font you're using?
@nirlichtman
@nirlichtman 3 ай бұрын
Cascadia Mono
@user-be2ml6vn9y
@user-be2ml6vn9y 3 ай бұрын
great video, but i have problems with this on mac, when i start server and client it works but when i write someting into console it doesnt show up on other side have a wonder full day everyone reading that :)
@nirlichtman
@nirlichtman 3 ай бұрын
What do you see when running strace/ltrace?
@ricardoteixeira5436
@ricardoteixeira5436 3 ай бұрын
Why did you use &?
@nirlichtman
@nirlichtman 3 ай бұрын
You mean when I used it to make a bitwise AND? Reason I used & over there is to check if a certain bit flag is enabled
@ricardoteixeira5436
@ricardoteixeira5436 3 ай бұрын
@@nirlichtman you speak funny words magic man, but thanks for the explanation, i shall study more.
@nirlichtman
@nirlichtman 3 ай бұрын
You can get more information about this on this article: en.wikipedia.org/wiki/Bit_field
@ricardoteixeira5436
@ricardoteixeira5436 2 ай бұрын
​@@nirlichtman coming here 1 month later to ty for this video, i had just copy pasted ur code and played with it but now i completely understand it, even bitwise ops! : D
@mustafa_el-rashied
@mustafa_el-rashied 4 ай бұрын
answer, peace or war ?
@nirlichtman
@nirlichtman 4 ай бұрын
peace is always better
@mustafa_el-rashied
@mustafa_el-rashied 4 ай бұрын
I hope all of your country's people are like you in this option ;)
@ericsonporfirio6578
@ericsonporfirio6578 4 ай бұрын
My fear is that a guy like you doesn't work in programming, so I think what the hell do I have to do to work?
@nirlichtman
@nirlichtman 4 ай бұрын
Don't worry, I worked as a programmer in 2 startups before I decided to go to University, I can indeed find a job as a programmer, but I decided to study in order to learn the theoretical side of CS and open more options.
@sollybrown8217
@sollybrown8217 4 ай бұрын
The man page is so slow to load on wsl wow.
Making Simple Shared Object (.so) in C on Linux
5:48
Nir Lichtman
Рет қаралды 7 М.
Creating a TCP Server in C++
30:31
Sloan Kelly
Рет қаралды 323 М.
[柴犬ASMR]曼玉Manyu&小白Bai 毛发护理Spa asmr
01:00
是曼玉不是鳗鱼
Рет қаралды 32 МЛН
Тяжелые будни жены
00:46
К-Media
Рет қаралды 5 МЛН
Glow Stick Secret (part 2) 😱 #shorts
00:33
Mr DegrEE
Рет қаралды 54 МЛН
Conforto para a barriga de grávida 🤔💡
00:10
Polar em português
Рет қаралды 103 МЛН
Advanced C #20: error handling
7:57
Charles Cabergs
Рет қаралды 2,6 М.
How it feels writing your first program in C# versus python…
0:59
LeMaster Tech
Рет қаралды 146 М.
Become a shell wizard in ~12 mins
12:25
CODE IS EVERYTHING
Рет қаралды 204 М.
What Happens When Booting Linux with Low Memory
5:11
Nir Lichtman
Рет қаралды 60 М.
image file formats explained in hindi - JPEG, PNG, GIF, TIFF, BMP etc
3:44
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2 МЛН
Drawing Graphics with C and Windows API is Easy
5:17
Nir Lichtman
Рет қаралды 25 М.
unlock the lowest levels of coding
7:05
Low Level Learning
Рет қаралды 219 М.
Error Correction - Computerphile
11:30
Computerphile
Рет қаралды 246 М.
How much charging is in your phone right now? 📱➡️ 🔋VS 🪫
0:11
What’s your charging level??
0:14
Татьяна Дука
Рет қаралды 6 МЛН
iPhone green Line Issue #iphone #greenlineissue #greenline #trending
0:10
Rk Electronics Servicing Center
Рет қаралды 4,8 МЛН
Я Создал Новый Айфон!
0:59
FLV
Рет қаралды 4,2 МЛН
🤔Почему Samsung ПОМОГАЕТ Apple?
0:48
Technodeus
Рет қаралды 390 М.