Making Minimalist Chat Server in C on Linux

Поділитися
Вставка
  • Опубліковано 3 лют 2025

КОМЕНТАРІ • 125

  • @Kirmo13
    @Kirmo13 Рік тому +150

    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 Рік тому +11

      what the actual fuck? how do you do that?

    • @JayHey111
      @JayHey111 Рік тому +6

      i thought it was just a themed terminal application to look like the terminal from win 11

    • @guigs4467
      @guigs4467 Рік тому +16

      actual psychopath

    • @JayHey111
      @JayHey111 Рік тому

      @@guigs4467 yes a bit

    • @qxħ
      @qxħ Рік тому +1

      talk to those who uses a old pc where he do tasks like linux on windows 10.

  • @space9824
    @space9824 Рік тому +60

    I love the way you just get right down to the business of writing code, it's so refreshing.

  • @anggaradotnet
    @anggaradotnet Рік тому +8

    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 Рік тому +22

    You have a great skill in using man pages btw

    • @KaiusKC
      @KaiusKC Рік тому +1

      Literally RTFM

  • @Crux161
    @Crux161 Рік тому +52

    The C classes I _should have taken_ 😅 better late than never

  • @abrahampo1801
    @abrahampo1801 Рік тому +4

    Men i cant get rid of using copilot and this guy doesnt need internet at all, epic dude

  • @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 11 місяців тому +1

    one of the best programming videos I've ever seen on youtube. great job!!

  • @MadMathMike
    @MadMathMike Рік тому +52

    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  Рік тому +12

      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 Рік тому

      @@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 Рік тому +7

      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 9 місяців тому +2

      @@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 9 місяців тому

      @@tweetyguy7347 well if you want to move to a better syntax consider zig

  • @saturdaysequalsyouth
    @saturdaysequalsyouth Рік тому +8

    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  Рік тому +5

      Thanks! That is a good idea, it can help give more context.

  • @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

  • @alangraton2000
    @alangraton2000 Рік тому +1

    Pretty neat man. I loved (still loving) C during college

  • @sweetbabyalaska
    @sweetbabyalaska Рік тому +1

    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)

  • @AndrewTSq
    @AndrewTSq 12 днів тому

    I love that you do not use any autocomplete when writing!. I see it as extra "practice" when typing, to type better an faster. learning the musclememory more and more :) thanks for the tutorials! . Love the use of man. It feels like you actually learn things watching these videos.. otherwise its usually google, copy code snippet, change some few things in the copied code and... google next problem and in the end you have no clue what is going on lol. Can not wait for AI to start to generate more and more code to make me even dumber :)

  • @ssize_t
    @ssize_t 2 місяці тому

    Damn you made me realize I probably over complicated something I did at work (I'm a noob ofc).
    I needed a C program that could receive messages from a TCP server and write them on a file, and at the same time provide something like a chat with a TCP client. I did it with two threads, one for listening messages and writing on file, to other one to act like a chat. But I think I could just use a single thread and poll the two sockets. Debugging with two threads has been a pain in the ass. I'll definitely try to implement it tomorrow

  • @th3j0t46
    @th3j0t46 Рік тому +1

    Did something like this on my 2nd year at college :))
    Good stuff!

  • @MeineRespectirung
    @MeineRespectirung Рік тому +2

    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.

  • @urs4n313
    @urs4n313 Рік тому

    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  Рік тому

      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.

  • @pavfrang
    @pavfrang Рік тому +1

    Another exceptional video, thank you!

  • @leonvolq6179
    @leonvolq6179 Рік тому +1

    The peace is perfect, not to slow not too fast 🎉

  • @Tcrrxzz
    @Tcrrxzz 8 місяців тому +1

    I never knew C can do these things

  • @shahidkhan69
    @shahidkhan69 Рік тому +5

    I’ve always wondered how async code waits for IO. Bow I know, the poll function. Thanks

    • @nirlichtman
      @nirlichtman  Рік тому +3

      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

  • @thatonemailbox
    @thatonemailbox Рік тому +6

    I love your content! Could you write a minimalist regular expression engine at some point?

    • @nirlichtman
      @nirlichtman  Рік тому +3

      Thanks :) Yes, that is a good idea!

  • @tomershechner
    @tomershechner Рік тому

    רמה גבוהה ביותר. יש לך סגנון ייחודי, מסביר מה אתה עושה בלי הקדמות מיותרות. אהבתי במיוחד את השימוש הנרחב שלך בדפי מן, מראה איך להגיע לפתרון מהר בלי לרוץ כל שנייה לדפדפן.

  • @onurguzel16
    @onurguzel16 Рік тому +2

    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  Рік тому +5

      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.

  • @aah134-K
    @aah134-K Рік тому

    Keep up the amazing work, it is fun to see :)

  • @CYBERNETIC-ANGEL
    @CYBERNETIC-ANGEL 11 місяців тому

    learned a lot from this video. thanks

  • @novus7456
    @novus7456 Рік тому +1

    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.

  • @ivandimitrov4410
    @ivandimitrov4410 6 місяців тому

    this channel is a fucking gem..

  • @chroanamandros6820
    @chroanamandros6820 Рік тому

    I dont write C but man you make it look easyyy
    Great vidddd❤❤

  • @guillermoezequielperna9674
    @guillermoezequielperna9674 Рік тому

    Thank you very much for this content.

  • @mh7200
    @mh7200 Рік тому

    I use the Same setup! Nice 👍🏻

  • @bhavyakukkar
    @bhavyakukkar Рік тому

    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.

  • @lucaraymaekers6414
    @lucaraymaekers6414 3 місяці тому

    Hey, thanks for the video it was really interesting and the workflow is very nice. How do you get rid of the error while binding?

    • @nirlichtman
      @nirlichtman  3 місяці тому

      Thanks! to which error exactly are you referring ?

    • @lucaraymaekers6414
      @lucaraymaekers6414 3 місяці тому

      @@nirlichtman The error where it will still count the resource as busy, I found you had to use SO_REUSADDR and the error got away!
      Thank you again for the great video btw

  • @ItsCOMMANDer_
    @ItsCOMMANDer_ Рік тому +3

    How did you split your terminal lile that? It looks nice

    • @nirlichtman
      @nirlichtman  Рік тому +5

      Thanks! I use the window splitting feature built-in Vim, I have a video about that on my "Vim Tips" playlist

    • @NostraDavid2
      @NostraDavid2 Рік тому +1

      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.

  • @shahidkhan69
    @shahidkhan69 Рік тому

    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

  • @angelffg
    @angelffg Рік тому

    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  Рік тому +1

      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 Рік тому

      @@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.

  • @KaranChecker
    @KaranChecker Рік тому

    Amazing code.
    Maybe use a softer keyboard while recording.

  • @matweyrybakovskiy2952
    @matweyrybakovskiy2952 Рік тому

    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  Рік тому +1

      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 Рік тому

      @@nirlichtman Thank you)

  • @samarthtandale9121
    @samarthtandale9121 4 місяці тому

    My terminal upon entering command "man sockaddr" says 'No manual entry exists :('

    • @nirlichtman
      @nirlichtman  4 місяці тому

      What is your setup? make sure you have the relevant man pages package installed (ubuntu/debian: manpages-dev)

  • @buraksoykan2985
    @buraksoykan2985 Рік тому

    Ecole 42, Minitalk project same like that

  • @Kyoz
    @Kyoz Рік тому

    🤍
    Love every video that has C or minimalist in the title.

  • @nickbelanger5225
    @nickbelanger5225 Рік тому

    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  Рік тому

      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 :)

  • @ultratoz
    @ultratoz Рік тому

    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  11 місяців тому

      Do you have manpages-dev package installed?

  • @justinalejo4187
    @justinalejo4187 Рік тому

    how do you get your terminal and file to do that on the same tab?

    • @nirlichtman
      @nirlichtman  Рік тому

      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"

  • @cosmiclattemusic
    @cosmiclattemusic 6 місяців тому

    btw the wind sound in the background at 9:12

  • @rian0xFFF
    @rian0xFFF Рік тому

    help: better way to add data into a linked list without loops or inserting it directly? I need to read a file

    • @NostraDavid2
      @NostraDavid2 Рік тому

      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 Рік тому

      ​@@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 Рік тому

    I followed this code line by line and compiled it with gcc on mac, but messages are not displayed on the server/client.

    • @pythonicness
      @pythonicness Рік тому

      check your code thoroughly, cc version and libraries. Try to compile the code you have written in somewhere else.

    • @nirlichtman
      @nirlichtman  Рік тому

      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 Рік тому

      @@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.

  • @Benjaneb
    @Benjaneb Рік тому

    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 Рік тому

      :sp

    • @Benjaneb
      @Benjaneb Рік тому

      @@pajeetsingh This only splits the editor, not open a terminal

    • @pajeetsingh
      @pajeetsingh Рік тому

      He is using dwm I guess so it has bindings to do so.@@Benjaneb

    • @Benjaneb
      @Benjaneb Рік тому

      ​@@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 Рік тому

      Ok nvm apparently it's just because I use neovim, works like in the video with regular vim

  • @asifzamanpls
    @asifzamanpls Рік тому

    great video but i must ask, howd you get dwm working on windows?

    • @nirlichtman
      @nirlichtman  Рік тому +1

      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 Рік тому

      @@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!

  • @TomekLeks
    @TomekLeks Рік тому

    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  Рік тому

      What do you see when running strace/ltrace?

  • @ricardoteixeira5436
    @ricardoteixeira5436 11 місяців тому +1

    Why did you use &?

    • @nirlichtman
      @nirlichtman  11 місяців тому +1

      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 11 місяців тому

      @@nirlichtman you speak funny words magic man, but thanks for the explanation, i shall study more.

    • @nirlichtman
      @nirlichtman  11 місяців тому +1

      You can get more information about this on this article: en.wikipedia.org/wiki/Bit_field

    • @ricardoteixeira5436
      @ricardoteixeira5436 10 місяців тому

      ​@@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

  • @TunifyBasic
    @TunifyBasic Рік тому

    you need to do a setsockopt SOCK_REUSE or something like that

  • @calengo454
    @calengo454 Рік тому

    what's the name of the font you're using?

  • @mumk
    @mumk Рік тому

    interesting, thanks

  • @spyrosdev25
    @spyrosdev25 Рік тому

    please tell me what font you use!

    • @nirlichtman
      @nirlichtman  Рік тому

      On this vid I use my WSL setup on Windows Terminal and the terminal is configured with the Cascadia Mono font.

  • @robbirobson7330
    @robbirobson7330 Рік тому +2

    its basically like python

  • @justinnamilee
    @justinnamilee Рік тому

    Neato.

  • @guilherme5094
    @guilherme5094 Рік тому

    👍👍!

  • @mustafa_el-rashied
    @mustafa_el-rashied Рік тому

    answer, peace or war ?

  • @sollybrown8217
    @sollybrown8217 Рік тому

    The man page is so slow to load on wsl wow.

  • @ericsonporfirio6578
    @ericsonporfirio6578 Рік тому

    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  Рік тому

      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.