Making Minimalist Chat Server in C on Linux

Поділитися
Вставка
  • Опубліковано 22 гру 2024

КОМЕНТАРІ •

  • @Kirmo13
    @Kirmo13 11 місяців тому +146

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

      what the actual fuck? how do you do that?

    • @JayHey111
      @JayHey111 10 місяців тому +6

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

    • @guigs4467
      @guigs4467 10 місяців тому +16

      actual psychopath

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

      @@guigs4467 yes a bit

    • @qxħ
      @qxħ 10 місяців тому +1

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

  • @space9824
    @space9824 11 місяців тому +59

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

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

  • @pinuxman802
    @pinuxman802 11 місяців тому +21

    You have a great skill in using man pages btw

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

      Literally RTFM

  • @Crux161
    @Crux161 11 місяців тому +50

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

  • @TheBrunoRM
    @TheBrunoRM 10 місяців тому +1

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

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

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

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

  • @abrahampo1801
    @abrahampo1801 10 місяців тому +3

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

  • @baptistepasquier4174
    @baptistepasquier4174 11 місяців тому +4

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

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

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

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

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

  • @th3j0t46
    @th3j0t46 10 місяців тому +1

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

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

  • @ssize_t
    @ssize_t Місяць тому

    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

  • @urs4n313
    @urs4n313 11 місяців тому

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

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

    Another exceptional video, thank you!

  • @shahidkhan69
    @shahidkhan69 11 місяців тому +5

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

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

  • @aah134-K
    @aah134-K 11 місяців тому

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

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

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

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

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

    learned a lot from this video. thanks

  • @thatonemailbox
    @thatonemailbox 11 місяців тому +6

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

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

      Thanks :) Yes, that is a good idea!

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

  • @guillermoezequielperna9674
    @guillermoezequielperna9674 11 місяців тому

    Thank you very much for this content.

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

    btw the wind sound in the background at 9:12

  • @chroanamandros6820
    @chroanamandros6820 11 місяців тому

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

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

    this channel is a fucking gem..

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

    I never knew C can do these things

  • @shahidkhan69
    @shahidkhan69 11 місяців тому

    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

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

    I use the Same setup! Nice 👍🏻

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

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

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

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

  • @Kyoz
    @Kyoz 11 місяців тому

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

  • @ItsCOMMANDer_
    @ItsCOMMANDer_ 11 місяців тому +3

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

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

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

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

  • @nickbelanger5225
    @nickbelanger5225 11 місяців тому

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

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

  • @matweyrybakovskiy2952
    @matweyrybakovskiy2952 11 місяців тому

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

      @@nirlichtman Thank you)

  • @braz1080
    @braz1080 11 місяців тому

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

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

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

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

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

  • @tomershechner
    @tomershechner 11 місяців тому

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

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

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

      Thanks! to which error exactly are you referring ?

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

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

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

      Thanks for the feedback 👍

  • @ultratoz
    @ultratoz 11 місяців тому

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

      Do you have manpages-dev package installed?

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

    we can make with c++ like this ?

  • @Benjaneb
    @Benjaneb 11 місяців тому

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

      :sp

    • @Benjaneb
      @Benjaneb 11 місяців тому

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

    • @pajeetsingh
      @pajeetsingh 11 місяців тому

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

    • @Benjaneb
      @Benjaneb 11 місяців тому

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

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

  • @rian0xFFF
    @rian0xFFF 11 місяців тому

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

    • @NostraDavid2
      @NostraDavid2 11 місяців тому

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

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

    Ecole 42, Minitalk project same like that

  • @angelffg
    @angelffg 11 місяців тому

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

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

  • @justinalejo4187
    @justinalejo4187 11 місяців тому

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

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

      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"

  • @bhavyakukkar
    @bhavyakukkar 11 місяців тому

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

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

    Why did you use &?

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

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

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

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

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

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

  • @calengo454
    @calengo454 11 місяців тому

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

  • @asifzamanpls
    @asifzamanpls 11 місяців тому

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

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

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

  • @mumk
    @mumk 11 місяців тому

    interesting, thanks

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

    please tell me what font you use!

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

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

  • @TunifyBasic
    @TunifyBasic 11 місяців тому

    you need to do a setsockopt SOCK_REUSE or something like that

  • @KaranChecker
    @KaranChecker 11 місяців тому

    Amazing code.
    Maybe use a softer keyboard while recording.

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

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

      What do you see when running strace/ltrace?

  • @robbirobson7330
    @robbirobson7330 11 місяців тому +2

    its basically like python

  • @justinnamilee
    @justinnamilee 11 місяців тому

    Neato.

  • @mustafa_el-rashied
    @mustafa_el-rashied 11 місяців тому

    answer, peace or war ?

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

      peace is always better

    • @mustafa_el-rashied
      @mustafa_el-rashied 11 місяців тому

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

  • @guilherme5094
    @guilherme5094 11 місяців тому

    👍👍!

  • @sollybrown8217
    @sollybrown8217 11 місяців тому

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

  • @ericsonporfirio6578
    @ericsonporfirio6578 11 місяців тому

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

      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.