Making Minimalist Chat Server in C on Linux

Поделиться
HTML-код
  • Опубликовано: 29 окт 2024
  • Making a simple chat server and client using the C Programming Language and Linux Socket API.
    Code:
    github.com/nir...

Комментарии • 124

  • @Kirmo13
    @Kirmo13 9 месяцев назад +142

    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 9 месяцев назад +10

      what the actual fuck? how do you do that?

    • @JayHey111
      @JayHey111 9 месяцев назад +5

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

    • @guigs4467
      @guigs4467 8 месяцев назад +16

      actual psychopath

    • @JayHey111
      @JayHey111 8 месяцев назад

      @@guigs4467 yes a bit

    • @qxħ
      @qxħ 8 месяцев назад +1

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

  • @space9824
    @space9824 9 месяцев назад +59

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

  • @anggaradotnet
    @anggaradotnet 8 месяцев назад +6

    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

  • @Crux161
    @Crux161 9 месяцев назад +50

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

  • @pinuxman802
    @pinuxman802 9 месяцев назад +21

    You have a great skill in using man pages btw

    • @KaiusKC
      @KaiusKC 9 месяцев назад +1

      Literally RTFM

  • @MadMathMike
    @MadMathMike 9 месяцев назад +51

    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  9 месяцев назад +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 9 месяцев назад

      @@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 9 месяцев назад +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 6 месяцев назад +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 6 месяцев назад

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

  • @TheBrunoRM
    @TheBrunoRM 8 месяцев назад +1

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

  • @saturdaysequalsyouth
    @saturdaysequalsyouth 9 месяцев назад +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  9 месяцев назад +5

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

  • @abrahampo1801
    @abrahampo1801 9 месяцев назад +2

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

  • @quicksolution5881
    @quicksolution5881 9 месяцев назад +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

  • @baptistepasquier4174
    @baptistepasquier4174 9 месяцев назад +4

    Very good video !! Loving those short tutorials.
    I've done quite a similar project but not by using socket but UNIX signals.

  • @alangraton2000
    @alangraton2000 9 месяцев назад +1

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

  • @sweetbabyalaska
    @sweetbabyalaska 9 месяцев назад +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)

  • @th3j0t46
    @th3j0t46 9 месяцев назад +1

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

  • @MeineRespectirung
    @MeineRespectirung 9 месяцев назад +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.

  • @pavfrang
    @pavfrang 9 месяцев назад +1

    Another exceptional video, thank you!

  • @urs4n313
    @urs4n313 9 месяцев назад

    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  9 месяцев назад

      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 9 месяцев назад +1

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

  • @thatonemailbox
    @thatonemailbox 9 месяцев назад +6

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

    • @nirlichtman
      @nirlichtman  9 месяцев назад +3

      Thanks :) Yes, that is a good idea!

  • @onurguzel16
    @onurguzel16 9 месяцев назад +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  9 месяцев назад +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.

  • @Tcrrxzz
    @Tcrrxzz 5 месяцев назад +1

    I never knew C can do these things

  • @aah134-K
    @aah134-K 9 месяцев назад

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

  • @shahidkhan69
    @shahidkhan69 9 месяцев назад +5

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

    • @nirlichtman
      @nirlichtman  9 месяцев назад +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

  • @CYBERNETIC-ANGEL
    @CYBERNETIC-ANGEL 7 месяцев назад

    learned a lot from this video. thanks

  • @guillermoezequielperna9674
    @guillermoezequielperna9674 9 месяцев назад

    Thank you very much for this content.

  • @ItsCOMMANDer_
    @ItsCOMMANDer_ 9 месяцев назад +3

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

    • @nirlichtman
      @nirlichtman  9 месяцев назад +5

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

    • @NostraDavid2
      @NostraDavid2 9 месяцев назад +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.

  • @chroanamandros6820
    @chroanamandros6820 9 месяцев назад

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

  • @ivandimitrov4410
    @ivandimitrov4410 3 месяца назад

    this channel is a fucking gem..

  • @ultratoz
    @ultratoz 9 месяцев назад

    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  8 месяцев назад

      Do you have manpages-dev package installed?

  • @lucaraymaekers6414
    @lucaraymaekers6414 14 дней назад

    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  12 дней назад

      Thanks! to which error exactly are you referring ?

    • @lucaraymaekers6414
      @lucaraymaekers6414 12 дней назад

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

  • @mh7200
    @mh7200 8 месяцев назад

    I use the Same setup! Nice 👍🏻

  • @novus7456
    @novus7456 9 месяцев назад +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.

    • @nirlichtman
      @nirlichtman  9 месяцев назад

      Thanks for the feedback 👍

  • @Kyoz
    @Kyoz 9 месяцев назад

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

  • @tomershechner
    @tomershechner 9 месяцев назад

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

  • @angelffg
    @angelffg 9 месяцев назад

    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  9 месяцев назад +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 9 месяцев назад

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

  • @nickbelanger5225
    @nickbelanger5225 9 месяцев назад

    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  9 месяцев назад

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

  • @bhavyakukkar
    @bhavyakukkar 9 месяцев назад

    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  9 месяцев назад +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.

  • @shahidkhan69
    @shahidkhan69 9 месяцев назад

    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 9 месяцев назад

    Amazing code.
    Maybe use a softer keyboard while recording.

  • @asifzamanpls
    @asifzamanpls 9 месяцев назад

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

    • @nirlichtman
      @nirlichtman  9 месяцев назад +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 9 месяцев назад

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

  • @Benjaneb
    @Benjaneb 9 месяцев назад

    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 9 месяцев назад

      :sp

    • @Benjaneb
      @Benjaneb 9 месяцев назад

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

    • @pajeetsingh
      @pajeetsingh 9 месяцев назад

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

    • @Benjaneb
      @Benjaneb 9 месяцев назад

      ​@@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 9 месяцев назад

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

  • @matweyrybakovskiy2952
    @matweyrybakovskiy2952 9 месяцев назад

    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  9 месяцев назад +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 9 месяцев назад

      @@nirlichtman Thank you)

  • @justinalejo4187
    @justinalejo4187 9 месяцев назад

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

    • @nirlichtman
      @nirlichtman  9 месяцев назад

      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"

  • @samarthtandale9121
    @samarthtandale9121 Месяц назад

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

    • @nirlichtman
      @nirlichtman  29 дней назад

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

  • @robbirobson7330
    @robbirobson7330 9 месяцев назад +2

    its basically like python

  • @rian0xFFF
    @rian0xFFF 9 месяцев назад

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

    • @NostraDavid2
      @NostraDavid2 9 месяцев назад

      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 9 месяцев назад

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

  • @buraksoykan2985
    @buraksoykan2985 9 месяцев назад

    Ecole 42, Minitalk project same like that

  • @KernelKing1
    @KernelKing1 2 месяца назад

    we can make with c++ like this ?

  • @sournois90
    @sournois90 9 месяцев назад

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

  • @spyrosdev2533
    @spyrosdev2533 9 месяцев назад

    please tell me what font you use!

    • @nirlichtman
      @nirlichtman  8 месяцев назад

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

  • @braz1080
    @braz1080 9 месяцев назад

    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 9 месяцев назад

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

    • @nirlichtman
      @nirlichtman  9 месяцев назад

      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 9 месяцев назад

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

  • @mumk
    @mumk 9 месяцев назад

    interesting, thanks

  • @ricardoteixeira5436
    @ricardoteixeira5436 8 месяцев назад +1

    Why did you use &?

    • @nirlichtman
      @nirlichtman  8 месяцев назад +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 8 месяцев назад

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

    • @nirlichtman
      @nirlichtman  8 месяцев назад +1

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

    • @ricardoteixeira5436
      @ricardoteixeira5436 7 месяцев назад

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

  • @justinnamilee
    @justinnamilee 9 месяцев назад

    Neato.

  • @cosmiclattemusic
    @cosmiclattemusic 3 месяца назад

    btw the wind sound in the background at 9:12

  • @TunifyBasic
    @TunifyBasic 9 месяцев назад

    you need to do a setsockopt SOCK_REUSE or something like that

  • @TomekLeks
    @TomekLeks 8 месяцев назад

    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  8 месяцев назад

      What do you see when running strace/ltrace?

  • @guilherme5094
    @guilherme5094 9 месяцев назад

    👍👍!

  • @ericsonporfirio6578
    @ericsonporfirio6578 9 месяцев назад

    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  9 месяцев назад

      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.

  • @mustafa_el-rashied
    @mustafa_el-rashied 9 месяцев назад

    answer, peace or war ?

    • @nirlichtman
      @nirlichtman  9 месяцев назад

      peace is always better

    • @mustafa_el-rashied
      @mustafa_el-rashied 9 месяцев назад

      I hope all of your country's people are like you in this option ;)

  • @sollybrown8217
    @sollybrown8217 9 месяцев назад

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